Securing websockets for https use

This commit is contained in:
2022-10-11 19:28:05 +02:00
parent 138ebfb84d
commit a5ce23472a
5 changed files with 15 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
const ws = new WebSocket("ws://localhost:8989"); const ws = new WebSocket("wss://HOSTNAMEHERE:443");
let downloadname let downloadname
ws.onopen = () => { ws.onopen = () => {

View File

@@ -1,4 +0,0 @@
var server = require('./server')
var fs = require('fs')
server.createServer();

View File

@@ -1,18 +1,16 @@
function webServer() {
const fs = require('fs'); const fs = require('fs');
const WebSocket = require('ws'); const WebSocket = require('ws');
const https = require('https'); const https = require('https');
const server = new https.createServer({ const server = new https.createServer({
cert: fs.readFileSync('./sec_certs/server.crt'), cert: fs.readFileSync('./sec_certs/fullchain.pem'),
key: fs.readFileSync('./sec_certs/server.key') key: fs.readFileSync('./sec_certs/privkey.pem')
}); });
const wss = new WebSocket.Server({
port: 8989 const wss = new WebSocket.Server({server});
}, () => {
console.log('websocket server started!') console.log('websocket server started!')
})
const path = require('path') const path = require('path')
const pathPublic = path.join(__dirname, '../source') const pathPublic = path.join(__dirname, '../source')
let currentPath = pathPublic let currentPath = pathPublic
@@ -67,7 +65,7 @@ function webServer() {
}) })
}) })
}
exports.createServer = webServer; //Start the server
server.listen(443);