CORS: Axios call from static site to express.js backend blocked

I am having trouble making axios calls to my backend api on render (it works fine on my local dev environment). I can access my front-end at https://frontend.com but then after a certain timeout, I see in my console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mybackend.onrender.com:5000/something. (Reason: CORS request did not succeed). Status code: (null).

I am logging req.headers.host on the express.js side and despite req.headers.host matching res.header(“Access-Control-Allow-Origin”, “…”) the request does not succeed. req.headers.referer is “undefined”, or results in some IP address.

Any ideas on how I can further troubleshoot this?

1 Like

I found the problem: My back-end was listening on port 5000 but for some reason requests to http://render-domain:5000 were not going through, even though on the log, express.js was reporting “Listening on port 5000”. When I removed the port number from the request it was succesfully completed.