A
A
Anton Shelestov2018-12-11 20:23:37
Node.js
Anton Shelestov, 2018-12-11 20:23:37

Setting up a WebSocket connection over https?

Hello!
There is a client js:

let socket = io.connect('https://example.ru:3000');

There is server.js on the server:
var fs = require('fs');
let options = {
    key: fs.readFileSync('/etc/letsencrypt/live/example.ru/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/example.ru/fullchain.pem'),
    port: 3000,
};
let https = require('https').createServer(options);
let io = require('socket.io')(https);
let Redis = require('ioredis');

let redis = new Redis();

redis.psubscribe('channel_*');
redis.on('pmessage', function (pattern, channel, message) {
    //console.log('Message recieved: ' + message);
    //console.log('Channel: ' + channel);
    msg = JSON.parse(message);
    io.emit(channel, msg);
});

https.listen(3000, function () {
    console.log('Listening on Port: 3000');
});

node server starts and runs, but then there is no connection in the browser.
Writes: WebSocket connection to 'wss://example.ru:3000/socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established.
VPS: Apache, SSL per domain This is the
first time I've encountered such a task, can anyone tell me where to dig?
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question