0

I made a socket.io http server but now I want it to work with https.

I generated a certificate with letsencrypt and I want to use it for my app.

Server code

const fs = require('fs');
const server = require('https').createServer({
  key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
});
const io = require('socket.io')(server, {});

io.on('connection', socket => { console.log(socket.id); });

server.listen(3000);

I'm using socket.io@^2.3.0 and socket.io-client@^2.4.0 for the client

When i try to connect with the client I see no connection / error on the server.

This is how the client looks

const socket = require("socket.io-client")("https://example.com:3000")
socket.on("connect", () => {
    console.log("connected")
}

I've also tried with other URLs but still nothing:

const socket = require("socket.io-client")("http://example.com:3000")
const socket = require("socket.io-client")("https://example.com")
const socket = require("socket.io-client")("wss://example.com:3000")
const socket = require("socket.io-client")("wss://example.com")

0 Answers0