CORS Issue
Wasp version: 0.13.2
Backend: https://api.mydomain.com
I have read other issues regarding CORS and I have deployed everything as the documentation recommends:
I have a
serverSetup.ts
file which has the following:
As far as I know config.frontendUrl
should be already https://mydomain.com
but I have added since I am not able to get it working.
In main.wasp
I have added the following:
But I am still getting on client:
NGINX config:
Any idea what I am missing?8 Replies
Hi @mgp25. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided, it seems you're encountering a CORS (Cross-Origin Resource Sharing) issue with your Wasp application. Let's analyze the problem and suggest some solutions:
1. CORS Configuration:
Your CORS configuration in
serverSetup.ts
looks correct. However, there's a discrepancy between the domains you've mentioned. You're allowing <https://mydomain.com
,> but the error message shows the request is coming from <https://wislearn.io
.> Make sure to include all necessary domains in your CORS configuration Configuring Middleware (https://wasp-lang.dev/docs/advanced/middleware-config#1-customize-global-middleware).
2. Environment Variables:
Ensure that you've set the correct environment variables for your server, particularly WASP_WEB_CLIENT_URL
. This should be set to the URL where your frontend is hosted Deploying Manually (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables).
3. NGINX Configuration:
Your NGINX configuration looks fine for proxying requests to your backend. However, you might want to add some CORS headers to your NGINX configuration as an additional layer of security:
4. 404 Error:
The error message indicates a 404 status code, which suggests that the /auth/me
endpoint might not exist or is not accessible. Double-check that this route is correctly defined in your Wasp application.
5. API Namespace:
If you're using custom API endpoints, make sure you've configured the apiNamespace
correctly in your Wasp file Making Sure CORS Works (https://wasp-lang.dev/docs/advanced/apis#making-sure-cors-works).
6. Server URL:
Ensure that the WASP_SERVER_URL
environment variable is set correctly to <https://api.mydomain.com
> Deploying Manually (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables).
If you've verified all these points and are still experiencing issues, you might want to try upgrading to the latest Wasp version, as suggested in a similar case Discord support thread (https://discord.com/channels/686873244791210014/1201898985300971540).
If the problem persists, you may need to investigate further by adding more detailed logging on both the client and server sides to pinpoint exactly where the request is failing.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @mgp25, 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?Hey @mgp25, let's figure it out.
First question, do you have the client deployed somewhere? Can you share it?
After that, where are you seeing you the
XMLHttpRequest
error?
Debugging steps:
- Can you access the route by curl
ing the domain?
- Which headers does it return?
- If that's incorrect, can you access the route by curl
ing localhost?Hey @Filip ! Yes, I have deployed it on a VPS under a domain, I dont mind sharing the access via DM
XMLHttpRequest is shown in the web console (browser). So frontend not able to communicate to backend because of cors.
As per the headers returns when a curl is made to the backend:
Sure, send it into my DM and we'll take it from there 🙂
Actually, it was a fault on my end, with NGINX config.
Revealed a misconfiguration caused by certbot applying certain configs on its own.
I apologise for this but hopefully this helps out for other users facing similar issues.
Thank you!
Hey @mgp25
Do you mind if i pick your brain in dms regarding a similar issue with deploying via VPS?
Sure
No worries, it did smell like a reverse proxy issue.
For others reading this, I recommend following these steps: https://discord.com/channels/686873244791210014/1311720333681885214/1311732143281541150
And of course, checking the logs (nice thinking @mgp25): https://discord.com/channels/686873244791210014/1311720333681885214/1311778018326220902