CORS issue
I deployed https://github.com/vincanger/coverlettergpt backend and database to railways, and frontend to netflify and I am facing CORS issues
Frontend: https://66fcdba5764d005f23d60460--coverlettergpt.netlify.app/ when i go to login and try use the backend nodejs to login at https://aijobbot.up.railway.app/auth/me I am getting CORS issues
11 Replies
Hi @Jamesco. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the provided knowledge sources do not contain information on how to resolve CORS issues with Wasp when deploying to Railway and Netlify. I recommend checking the official Wasp documentation or their GitHub issues for potential solutions.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Jamesco, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Did you specify the frontend url env variable on the server? It is used to allow this url to make requests for your server.
@kapa.ai could this resolve the issue and if so can you provide more detailed information?
Wohooo @Gwaggli, you just became a Waspeteer level 7!
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, specifying the frontend URL in the server's environment variables could potentially resolve the CORS issue. In Wasp, the server needs to know the URL of the frontend to properly configure the Same-Origin Policy (CORS) headers. This is done by setting the
WASP_WEB_CLIENT_URL
environment variable to the URL where your frontend app is running.
Here's how you can do it:
1. In your .env.server
file (or .env
file if you haven't separated environment variables for the server and client), add the following line:
2. Save the file and deploy your application again. The server should now be aware of the frontend URL and configure the CORS headers accordingly.
Remember, this environment variable is required for the server to function correctly. If you're deploying your application manually, you can find more information about the required environment variables in the Wasp deployment documentation (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables).
Please note that the provided information is based on the Wasp framework. If you're not using Wasp, the process might be different.
Sources:
- Wasp Server Configuration (https://wasp-lang.dev/docs/advanced/accessing-app-config)
- Wasp Deployment Environment Variables (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Gwaggli, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Thanks Kapa!
@Jamesco You might want to check if you need to manually set the env variables on your server. They might get set automatically on your railway server but i am not sure.
I have the following Railways values set on the server:
DATABASE_URL="${{Postgres.DATABASE_URL}}"
JWT_SECRET="REMOVED"
WASP_SERVER_URL="https://server-production-0b41.up.railway.app"
WASP_WEB_CLIENT_URL="https://client-production-01be.up.railway.app"
GOOGLE_CLIENT_ID="REMOVED"
GOOGLE_CLIENT_SECRET="REMOVED"
OPENAI_API_KEY="REMOVED"
ALLOWED_CORS_ORIGINS="https://coverlettergpt.netlify.app,http://localhost:3000"
are these values correct or do i need to change something?
@Jamesco isnt your frontend url: Ihttps://66fcdba5764d005f23d60460--coverlettergpt.netlify.app/ ?
Here you have "https://client-production-01be.up.railway.app/" set as WASP_WEB_CLIENT_URL
And you also have a variable ALLOWED_CORS_ORIGINS which i dont know what it does (so probably its something you came up with?) and its pointing to another url again π
Quickly checked:
https://client-production-01be.up.railway.app/ this does not exist. So your env variable is false
https://coverlettergpt.netlify.app/ and https://66fcdba5764d005f23d60460--coverlettergpt.netlify.app/ seem to work but i guess you prefer the first one.
So you need to set WASP_WEB_CLIENT_URL=https://coverlettergpt.netlify.app/
And sidenote: you probably dont want to include the quotes(") in your variable value
Ok on railways server viarbales i have set:
DATABASE_URL="${{Postgres.DATABASE_URL}}"
JWT_SECRET="REMOVED"
WASP_WEB_CLIENT_URL="https://aijobbot.xyz/"
WASP_SERVER_URL="https://aijobbot.up.railway.app/"
GOOGLE_CLIENT_ID="REMOVED"
GOOGLE_CLIENT_SECRET="REMOVED"
OPENAI_API_KEY="REMOVED"
Which appears to have resolved it https://aijobbot.xyz/login
@Gwaggli i GREATLY apprecaite your help!
Not sure if you are familiar with this project? I got google auth working but lightning login is using localhost, which obviously wont work on the internet any idea how to resolve this, although i understand it is outside of the scope of this ticket. just wondering if you have experince with this i am very well versed on the bitcoin lightning network, although having trouble getting this work in the web application
@Jamesco Happy I could help!
Sorry, sadly I dont know lightning so I am not sure. But looks like either some other env variables are wrong and pointing to localhost or you have localhost somewhere in your code hardcoded which is probably not how it should be. But hard to tell without seeing the code and not knowing the framework π
@Gwaggli thanks for stepping up π you are the real MVP!
@Vinny (@Wasp) made CoverletterGPT and maybe he can jump in, he's coming back next week from his vacation π
Yep i think i got it all figured out! thanks i will close this π