From 94a7b319f68e31bfedc5b3f1d4ec9531fff427bd Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 25 Aug 2023 00:26:51 +0200 Subject: [PATCH] Fixed server crashes while one of two ports are in use --- config.json | 2 +- serverSideScript.js | 1 + svr.js | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index 517dfa2..76fd53d 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,7 @@ "port": 80, "pubport": 80, "page404": "404.html", - "timestamp": 1692477525860, + "timestamp": 1692915666757, "blacklist": [], "nonStandardCodes": [], "enableCompression": true, diff --git a/serverSideScript.js b/serverSideScript.js index 99b7b6d..255ae32 100644 --- a/serverSideScript.js +++ b/serverSideScript.js @@ -67,6 +67,7 @@ if(href == "/hello.svr") { //Prevent open proxy callServerError(403,"SVR.JS-exampleproxy"); //Server error serverconsole.errmessage("Client fails to recieve content."); //Log into SVR.JS + return; } var hdrs = req.headers; hdrs["Host"] = (hn == "this" ? req.headers.host : hn); diff --git a/svr.js b/svr.js index 2b66ccd..85d1e30 100644 --- a/svr.js +++ b/svr.js @@ -4863,11 +4863,17 @@ function start(init) { if (!cluster.isPrimary) { - if (secure) { - server.listen(sport); - if (!disableNonEncryptedServer) server2.listen(port); - } else { - server.listen(port); + try { + server.listen(secure ? sport : port); + } catch(err) { + if(err.code != "ERR_SERVER_ALREADY_LISTEN") throw err; + } + if (secure && !disableNonEncryptedServer) { + try { + server2.listen(port); + } catch(err) { + if(err.code != "ERR_SERVER_ALREADY_LISTEN") throw err; + } } }