How to redirect from www to non www
Hi everyone, I have this little problem that sometimes some websites redirect my non www website to a www version, and because of the wasp web client url (I guess that's the reason why) being set to non www, the backend won't work, and it throws CORS errors. What do you suggest?
7 Replies
Hi @ChilledGab. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. However, I can tell you that the
WASP_WEB_CLIENT_URL
environment variable is indeed used to specify the URL of where the frontend is running. If this URL is not set correctly, it could lead to CORS errors.
You might want to ensure that the WASP_WEB_CLIENT_URL
is set to the exact URL where your frontend is being served, including whether it uses www
or not. If you're serving your app from a subdirectory, make sure that the WASP_WEB_CLIENT_URL
also includes that base directory. You can find more information about this in the Wasp documentation (https://wasp-lang.dev/docs/project/client-config#base-directory).
As for the redirection from non-www to www, this is typically handled at the DNS or server level, and it's not something that Wasp directly controls. You might want to check your DNS settings or your server configuration to ensure that they're not automatically redirecting traffic in a way that's causing these CORS errors.
If you're still having trouble, I recommend reaching out to the Wasp community on their Discord server (https://discord.com/channels/686873244791210014) or opening an issue on the Wasp GitHub repository (https://github.com/wasp-lang/wasp/issues). They're usually very responsive and should be able to help you troubleshoot this issue.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ChilledGab, 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?I tried doing the 'forwarding' subdomain on Godaddy but it really doesn't work, so I was wondering if I could do it on app level @kapa.ai
Let me check the knowledge base for you. One moment! :books:
----------------------
Unfortunately, handling redirection from
www
to non-www
(or vice versa) at the application level is not typically recommended or efficient. This is because by the time the request reaches your application, it's already been routed to the www
or non-www
version of your domain, and changing it at that point can lead to unnecessary complications.
This kind of redirection is usually handled at the DNS or server level. Since you mentioned that you're having trouble with GoDaddy, it might be worth reaching out to their support for assistance, or considering other DNS providers that might offer more flexibility or control over your DNS settings.
In the context of Wasp and the WASP_WEB_CLIENT_URL
environment variable, it's important to ensure that this variable matches the exact URL where your frontend is being served, including whether it uses www
or not. If there's a mismatch between this environment variable and the actual URL of your frontend, it could lead to CORS errors.
If you're still having trouble, I recommend reaching out to the Wasp community on their Discord server (https://discord.com/channels/686873244791210014) or opening an issue on the Wasp GitHub repository (https://github.com/wasp-lang/wasp/issues). They're usually very responsive and should be able to help you troubleshoot this issue.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ChilledGab, 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?Basically if I add it on Godaddy it override some A entries, and conflict with the certificate set in the A entry for fly.io, any advice?
Ok, let me get this right:
1. You are using GoDaddy for your client domain?
2. GoDaddy has some redirect rules to redirect to www?
3. You are using Fly to host your app?
Hello @miho , sorry for replying just now, Yes I'm using GoDaddy. I tried using the subdomain forwarding rule with no luck, and I'm using Fly
You should setup your domain to have only one A record point to the Fly IPv4 address and one AAAA record point to the Fly IPv6 address
And here's how to setup a custom domain on Fly in Wasp docs: https://wasp-lang.dev/docs/advanced/deployment/cli#using-a-custom-domain-for-your-app
Deploying with the Wasp CLI | Wasp
Wasp CLI can deploy your full-stack application with only a single command.