RunOnFlux / flux

Flux, Your Gateway to a Decentralized World. https://home.runonflux.io https://api.runonflux.io https://docs.runonflux.io https://source.runonflux.io https://wiki.runonflux.io
https://home.runonflux.io
GNU Affero General Public License v3.0
232 stars 309 forks source link

Feature: rework websockets #1344

Closed MorningLightMountain713 closed 4 months ago

MorningLightMountain713 commented 4 months ago

What this pull does

I have this running on a live node now.

Can just do this now, and it sorts everything out, including all the express routes, websocket and socket.io stuff:

  const httpServer = new fluxServer.FluxServer();
  const httpsServer = new fluxServer.FluxServer({
    mode: 'https', key, cert, expressApp: httpServer.app,
  });

  await httpServer.listen(apiPort);
  log.info(`Flux listening on port ${apiPort}!`);

  await httpsServer.listen(apiPortHttps);
  log.info(`Flux https listening on port ${apiPortHttps}!`);

This pull fixes an issue we were having where the native websocket server was greeding all the websocket upgrades, so socket.io was forced to use polling only.

Now we handle the http upgrade manually, and pass this on based on the path to the correct server.

This prevents these errors in the console:

Screenshot 2024-06-14 at 8 36 24 PM

ToDo:

MorningLightMountain713 commented 4 months ago

I've tested this on a node running ubuntu 18 and nodejs 14 - inbound / outbound connections work fine.

I've tested socket.io with the debug page - works fine.

I haven't tested the terminal page (no apps to connect to) - I assume this works if the debug does.