2
votes

I have a nodejs express Rest API and I want to add websocket support. I'm using this boilerplate for the api part and added this library and socket.io to use websockets in the same project (I'm not sure if it matters).

My websockets work as expected without the Rest API but as soon as I make an http request to my API, connections to the websocket fail with the following error:

WebSocket connection to 'ws://localhost:3000/socket.io/?EIO=3&transport=websocket' failed: Invalid frame header

Already established connections still work though. This problem remains until I restart my server.

I found a lot of different possible causes for this error but none of which really helped me.

Edit: This is how I connect to the websockets.

const rooms = io.connect(
    'http://localhost:3000/rooms',
    { transports: ['websocket'] }
);
1

1 Answers

0
votes

I solved this problem by switching my stack to nestjs. The problem was probably because both websocket and rest api were running on the same port