An example of using http-proxy to proxy WebSocket requests to a separate server.
npm installnpm start
(ornpm run start:devto use nodemon & show debug messages)- Open http://localhost:4000 in the browser and check the console
To show debug messages in the browser use:
localStorage.setItem( 'debug', 'socket.io-client:*,-socket.io-client:socket' );To verify that sockets are being used instead of polling, open the dev tools Network tab and find the request using the websocket protocol.
It should have a status code of 101 Switching Protocols and it's frames tab should show all the incoming ping messages from the server.
- Socket.io will still do some (~3) initial polling requests before
upgradeing to a WebSocket connection.
If you change the clientsidetransportstotransports : ['websocket']these initial polling requests will stop but you lose the polling fallback.