Skip to content

v2 client can't connect to v4 server due to cors issues #4204

Discussion options

You must be logged in to vote

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 withCredentials to false on the client (it now defaults to false in v3/v4):

io(`http://localhost:5555`, {
  path: "/realtime",
  query: {
    token: userLocalToken
  },
  forceNew: true,
  withCredentials: false
});

Reference: https://socket.io/docs/v4/client-options/#withcredentials

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@backspacerhino
Comment options

Answer selected by backspacerhino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants