From 2ec6b564f5a4d63887782fccec428daa46491b14 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 10 Sep 2023 18:37:09 +0200 Subject: [PATCH] Improve web root error handling --- config.json | 4 ++-- svr.js | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index 76c1b32..489d4b8 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,7 @@ "port": 80, "pubport": 80, "page404": "404.html", - "timestamp": 1694334249412, + "timestamp": 1694363783457, "blacklist": [], "nonStandardCodes": [], "enableCompression": true, @@ -102,4 +102,4 @@ "errorPages": [], "useWebRootServerSideScript": true, "exposeModsInErrorPages": true -} +} \ No newline at end of file diff --git a/svr.js b/svr.js index 21cdd71..5938ae0 100644 --- a/svr.js +++ b/svr.js @@ -1151,11 +1151,12 @@ if (configJSON.rewriteDirtyURLs != undefined) rewriteDirtyURLs = configJSON.rewr if (configJSON.errorPages != undefined) errorPages = configJSON.errorPages; if (configJSON.useWebRootServerSideScript != undefined) useWebRootServerSideScript = configJSON.useWebRootServerSideScript; if (configJSON.exposeModsInErrorPages != undefined) exposeModsInErrorPages = configJSON.exposeModsInErrorPages; -if (configJSON.wwwroot != undefined) { - var wwwroot = configJSON.wwwroot; - if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(wwwroot); -} else { - if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(__dirname); + +var wwwrootError = null; +try { + if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(configJSON.wwwroot != undefined ? configJSON.wwwroot : __dirname); +} catch(err) { + wwwrootError = err; } // Compability for older mods @@ -4871,6 +4872,7 @@ function start(init) { if (netIPs.indexOf(listenAddress) > -1) throw new Error("SVR.JS can't listen on subnet address."); } if(certificateError) throw new Error("There was a problem with SSL certificate/private key: " + certificateError.message); + if(wwwrootError) throw new Error("There was a problem with your web root: " + wwwrootError.message); } // Information about starting the server