Home > Software engineering >  Error connecting to socket.io server, changed code from websocket to socket.io
Error connecting to socket.io server, changed code from websocket to socket.io

Time:09-06

I'm currently using websocket library on both nodejs backend and JS client.

I'm trying to change to socket.io, I managed to write the code for both sides however I'm unable to connect to the server from my client.

On the console of my browser I see the error and realised that the address is being changed by the socketio library.

websocket: wss://domain.com/asset-ws/ ==> works fine

socketio: auto changes the url to wss://domain.com/socket.io/?EIO=4&transport=websocket

The error: WebSocket connection to 'wss://domain.com/socket.io/?IO=4&transport=websocket' failed.

Is it something to do with my nginx config?

Any help would be much appreciated.

Thank you

CodePudding user response:

By default socket.io url adds the "/socket.io" path.

In my Nginx config I'm already using a custom path add, so I just specified a path on the io server config, like so:

const io = new Server(server, {
  path: '/' 
});

This way the default path would be overwritten.

  • Related