rpuls / medusajs-2.0-for-railway-boilerplate

Monorepo including medusajs 2.0 backend and storefront
25 stars 32 forks source link

Connecting to custom domain #7

Closed compelinnovations closed 2 weeks ago

compelinnovations commented 2 weeks ago

When I connect a custom domain to Railway, I get a CORS error.

...up.railway.app/auth/user/emailpass' from origin 'https://custom-domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

rpuls commented 2 weeks ago

Hey ;)

Are you getting this error when trying to login to your admin dashboard, after setting up custom domain on the backend container in Railway?

compelinnovations commented 2 weeks ago

Hi man, yes that is correct.

rpuls commented 2 weeks ago

Okay. I saw the same behavior as you. I can see that the request is made using the CORS setting from before the domain is setup. This is because during the build phase the medusa config is generated with the provided CORS settings, and at this point in time (before setup custom domain) they are some railway doamin.

So what I did to solve it, was to redeploy the backend after setting up the domain.

image

Then the app will build again, but this time with the custom domain, and the medusa-config will be generated with the correct CORS url.

Please try this and let me know if you are able to login :)

compelinnovations commented 2 weeks ago

Okay. I saw the same behavior as you. I can see that the request is made using the CORS setting from before the domain is setup. This is because during the build phase the medusa config is generated with the provided CORS settings, and at this point in time (before setup custom domain) they are some railway doamin.

So what I did to solve it, was to redeploy the backend after setting up the domain.

image

Then the app will build again, but this time with the custom domain, and the medusa-config will be generated with the correct CORS url.

Please try this and let me know if you are able to login :)

This worked! Thank you.