-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest possible wrong Socket.IO URL instead of CORS error #1979
Comments
+1 |
would be useful |
@rauchg can you explain a little bit the situation? I'm having this cors trouble and I can't find a solution to it. I'm using express and socket.io, on express side I've cors package which enable cors for all domains, than on socketio i'm using the The express/socket server is on a different subdomain than the client but all normal requests work pretty good but when it comes to socketio it doesn't set the headers.
|
Having the same issue, can't find a fix. anyone any idea? |
The close event will now include additional details to help debugging if anything has gone wrong. Example when a payload is over the maxHttpBufferSize value in HTTP long-polling mode: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport error" // in that case, details is an error object console.log(details.message); "xhr post error" console.log(details.description); // 413 (the HTTP status of the response) // details.context refers to the XMLHttpRequest object console.log(details.context.status); // 413 console.log(details.context.responseText); // "" }); ``` Note: the error object was already included before this commit and is kept for backward compatibility Example when a payload is over the maxHttpBufferSize value with WebSockets: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport close" // in that case, details is a plain object console.log(details.description); // "websocket connection closed" // details.context is a CloseEvent object console.log(details.context.code); // 1009 (which means "Message Too Big") console.log(details.context.reason); // "" }); ``` Example within a cluster without sticky sessions: ```js socket.on("close", (reason, details) => { console.log(details.context.status); // 400 console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}' }); ``` Note: we could also print some warnings in development for the "usual" errors: - CORS error - HTTP 400 with multiple nodes - HTTP 413 with maxHttpBufferSize but that would require an additional step when going to production (i.e. setting NODE_ENV variable to "production"). This is open to discussion! Related: - socketio/socket.io#3946 - socketio/socket.io#1979 - socketio/socket.io-client#1518
There is still such a problem, and it seems that it has not been solved |
@sugar258596 the problem is that I don't think we can really tell a CORS issue from a network issue, since the preflight requests are automatically sent by the browser. The XMLHttpRequest object does not give much information:
Open to discuss about this though! |
A lot of people seem to be mistaking the error
No 'Access-Control-Allow-Origin' header is present on the requested resource
for lack of CORS support in Socket.IO.This seems to be due to usually trying to initialize a socket to the wrong URL. The URL exists and responds, but obviously it doesn't set CORS headers. And even if it did, it wouldn't be where the socket.io server is hosted.
Maybe we could
console.warn
in these situations to warn the developer about a potential URL error.The text was updated successfully, but these errors were encountered: