1

I'm developing an application in ReactJS (18.2) using Vite (4.1) and Socket.IO-client (4.6) and everything works correctly locally, while running in dev mode (npm run dev) and also after deploying (npm run build + npm run preview).

However, when trying to use this deploy on Github Pages or Netlify, the application simply does not seem to run any of the features related to Socket.IO. It also doesn't send any type of error to the console, preventing me from being able to understand what could be going wrong.

I did different tests, running the application on Github and Netlify, trying different configurations on Vite, but the problem persists.

One of the possible solutions I found was to add the command { transports: ['websocket'] } to the socker.io connection parameters:

const socket = io(SERVERURL, {
  transports: ['websocket', 'polling', 'flashsocket'],
  path: '/SERVERPATH',
  forceNew: true,
  reconnectionAttempts: 3,
  timeout: 2000,
});

I would like to understand what could be going wrong.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

The issue was resolved by changing the URL of the websocket server connection from HTTP to to WSS.

const socket = io(wss://urlofserver.com, { transports: ['websocket'], path: '/SERVERPATH', forceNew: true, reconnectionAttempts: 3, timeout: 2000, });