Express server with socket.io getting cors error: No 'Access-Control-Allow-Origin' header is present on the requested resource despite it being set for both express and socket.io

I am using free tier web service running node js.

My code sets up a server with express and then also create a socket.io server instance.

Running my server locally on http://localhost:8080, I can connect from my front end development server running at http://localhost:3000 and from the same front end code hosted at vercel with an entirely different domain. both can connect without returning cors errors.

My backend server is now hosted on render and I can access API routes such as [renderURL]/currentgame or /users which display appropriate information.

however my client is unable to connect via websocket to the socket.io server.

in the below image i am connecting to my server running locally with the expected response header.

in the below image i am connecting to my server running on render, i noticed the x-frame-options is SAMEORIGIN and wonder if this is an issue.

i do have a render ticket open which was responded to stating because its a cors issue its an issue with my application but I’m at a loose end as to what it could be.

ticket number: 68684

to add:

i manually add cors for the socket and express to allow local dev server and my vercel hosted domain:


to further add, I have hosted the same code to AWS EC2 instance without any issue or cors errors being thrown

Hi there,

You need to use port 80/443 to access your services, using port 8080 will not work. CORS errors occur because the forbidden response is coming from our proxy and will not have any CORS headers.

Regards,

Keith
Render Support, UTC+10 :australia:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.