1

I am working on a small application that is hosted via node.js and uses socket.io for quick communication. For now it was only in development so it was fine. However now i would like to switch from ws:// to wss:// but dont really know where to start. I tried to research online but there is not much on the topic.

index.js (server)

const path = require("path");
const express = require("express");
const app = express();
const cors = require("cors");
const config = require("./config");
const webRoute = require("./lib/routes/web");
const widgetsRoute = require("./lib/routes/widgets");
const errorsHandler = require("./lib/handlers/errors");
const corsHandler = require("./lib/handlers/cors");

app.use(cors(corsHandler));

app.use(express.static(path.join(__dirname, "/public")));

app.use("/", webRoute);
app.use("/widgets", widgetsRoute);

app.use(errorsHandler);

app.listen(4118, "0.0.0.0");

const io = require("socket.io").listen(
  require("http")
    .createServer()
    .listen(4113, "0.0.0.0")
);

require("./lib/inits/socket")(io);

client:

this.socket = io("http://example.org:4113");

In the network tab i can see that socket.io is using ws:// in one of its calls.

How can i modify this so it uses wss instead?

Mevia
  • 1,517
  • 1
  • 16
  • 51
  • Related "Is it possible to force socket.io to use wss instead of ws, without having to change to https" - https://stackoverflow.com/questions/41426495/is-it-possible-to-force-socket-io-to-use-wss-instead-of-ws-without-having-to-ch – Ivar Dec 19 '19 at 10:17
  • 1
    its not related, i dont want to force anything, i am asking how to configure socket.io to use wss, i saw this topic, there is nothing there to help me. – Mevia Dec 19 '19 at 10:23
  • You are starting a client connection with `http` and not with `https` or even with `wss`, this is why I mentioned a related issue. When using `http` your client will most likely upgrade to using `ws` as far as I understand. BTW their documentation does not mention anything about `wss` or `https` which makes it quite confusing. – Ivar Dec 19 '19 at 10:48
  • I found focumentation of `ws` module is clearer about how to set up `wss` https://github.com/websockets/ws#external-https-server – Ivar Dec 19 '19 at 10:51
  • this is websockets, socket.io is not the same as websocket, if i was using native websocket there wouldnt be any problem. – Mevia Dec 19 '19 at 10:52
  • Indeed, I do not disagree, but comparison puts this question in a clearer background. Still my argument about not using "https" or "wss" on the client stands. – Ivar Dec 19 '19 at 10:58

0 Answers0