v2 client can't connect to v4 server due to cors issues #4204
-
Hi, I have a v2 client that works okay with v2 server. Now I upgraded server to v4. According to this, v2 client should work with v4 server given that allowEIO3: true When I try with v4 client it works okay, but when I try with v2 client from my index.html with js file I get:
The most confusing thing for me here is And when I go to that link I get:
Here is my configuration on both server and client Server:
Client:
The goal is to upgrade server to v4 and for users using v2 to be able to connect. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you need to include the cookies, you need to send the proper CORS headers on the server: this.io = new Server(AdonisServer.instance!, {
path: '/realtime',
allowEIO3: true,
cors: {
origin: "*",
credentials: true
}
}) Reference: https://socket.io/docs/v4/server-options/#cors Else, you can set the io(`http://localhost:5555`, {
path: "/realtime",
query: {
token: userLocalToken
},
forceNew: true,
withCredentials: false
}); Reference: https://socket.io/docs/v4/client-options/#withcredentials |
Beta Was this translation helpful? Give feedback.
If you need to include the cookies, you need to send the proper CORS headers on the server:
Reference: https://socket.io/docs/v4/server-options/#cors
Else, you can set the
withCredentials
to false on the client (it now defaults tofalse
in v3/v4):Reference: https://socket.io/docs/v4/client-options/#withcredentials