WebSockets do not work with ssl?

Hello! Websocket refuse to work via ssl, through an unsecure connection everything is fine. If you connect using wss:// , the browser console says "WebSocket connection to 'wss://localhost:1001/' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED" . What could be the problem?
Server Code :
// require
var http = require("https");
var fs = require("fs");

// http
var privateKey = fs.readFileSync('site.key').toString();
var certificate = fs.readFileSync('final.crt').toString();

var options = {
key:privateKey,
cert:certificate
};

var server = http.createServer(options).listen(8080);

server.on("request", function (req, res){

 fs.readFile("./index.html", function(d1, d2){
 Res. writeHead(200, {'Content-Type':'text/html'});
Res. write(d2.toString());
Res. end();
});

});

// websocketServer

var ws = require("ws");

var newWs = new ws.Server({
port:1001,
server:server,
});

newWs.on("connection", function (ws){

 // processing connection
});


Client code:
var ws = new WebSocket('wss://localhost:1001');
June 3rd 19 at 19:03
2 answers
June 3rd 19 at 19:05
Solution
so the server listens on 8080...
Yes, https and websocket 1001 - Zack.Ullri commented on June 3rd 19 at 19:08
June 3rd 19 at 19:07
Try to add:

var options = {
key:privateKey,
cert:certificate
requestCert: false,
rejectUnauthorized: false

};

Find more questions by tags WebSocket