2 months ago
Access to XMLHttpRequest at 'https://scalpx-backend-production.up.railway.app/api/auth/email' from origin 'https://scalpx-frontend-production.up.railway.app' 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.
index-BfEnmEWl.js:1564 Email verification failed: ie {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
(anonymous) @ index-BfEnmEWl.js:1564
scalpx-backend-production.up.railway.app/api/auth/email:1 Failed to load resource: net::ERR_FAILEDI setup a CORS in my code to https://scalpx-frontend-production.up.railway.app
router.Use(cors.New(cors.Config{
AllowOrigins: []string{cfg.CORS.Origin},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))But can't pass requests. Does railway has special approach to handle CORS?
1 Replies
2 months ago
No Railway doesn't have a special CORS setup, is for sure something related to the server/middleware configuration. Did you check if the preflight request (OPTIONS) is getting a response that includes Access-Control-Allow-Origin ?
Could you share the network tab of a request?
Be sure that you define CORS router config before any api config.
Try to see if the preflight request return Access-Control-Allow-Origin: https://scalpx-frontend-production.up.railway.app and be sure that CORS middleware is in same flow of the one handling the api path.
Also try to specify the AllowOrigins with hardcoded string just to be sure.
Status changed to Solved brody • about 2 months ago