From b88b357b55022cc17b202529d4227d82bc91f23a Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 2 Sep 2021 20:18:27 +0800 Subject: [PATCH] add support for https --- server/server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index d4fe668b3..ecdd65025 100644 --- a/server/server.js +++ b/server/server.js @@ -6,6 +6,7 @@ const { sleep, debug, TimeLogger, getRandomInt } = require("../src/util"); console.log("Importing Node libraries") const fs = require("fs"); const http = require("http"); +const https = require("https"); console.log("Importing 3rd-party libraries") debug("Importing express"); @@ -45,9 +46,21 @@ console.info("Version: " + checkVersion.version); const hostname = process.env.HOST || args.host; const port = parseInt(process.env.PORT || args.port || 3001); +// SSL +const sslKey = process.env.SSL_KEY || args.ssl_key || undefined; +const sslCert = process.env.SSL_CERT || args.ssl_cert || undefined; + console.log("Creating express and socket.io instance") const app = express(); -const server = http.createServer(app); + +let server; + +if (sslKey && sslCert) { + https.createServer(app); +} else { + http.createServer(app); +} + const io = new Server(server); app.use(express.json())