fix: use web root from configJSON.wwwroot for SVR.JS 4.2.0 or newer

This commit is contained in:
Dorian Niemiec 2024-12-09 15:44:50 +01:00
parent 34b95402c2
commit af9bf140ff

View file

@ -41,6 +41,19 @@ if (typeof scgiConfO.multiConfig == "object" && scgiConfO.multiConfig !== null)
} }
var disableModExposeSupported = process.versions.svrjs && process.versions.svrjs.match(/^(?:Nightly-|(?:[4-9]|[123][0-9])[0-9]*\.|3\.(?:[1-9][0-9]+\.|9\.(?:[1-9])|4\.(?:(?:[3-9]|[12][0-9])[0-9]+|29)))/i); var disableModExposeSupported = process.versions.svrjs && process.versions.svrjs.match(/^(?:Nightly-|(?:[4-9]|[123][0-9])[0-9]*\.|3\.(?:[1-9][0-9]+\.|9\.(?:[1-9])|4\.(?:(?:[3-9]|[12][0-9])[0-9]+|29)))/i);
var normalizedWebrootSupported = process.versions.svrjs && process.versions.svrjs.match(/^(?:Nightly-|(?:[5-9]|[1234][0-9])[0-9]*\.|4\.(?:(?:[1][0-9]|[2-9])+\.))/i);
function normalizeWebroot(currentWebroot) {
if (currentWebroot === undefined) {
return process.cwd();
} else if (!path.isAbsolute(currentWebroot)) {
return (
process.cwd() + (os.platform() == "win32" ? "\\" : "/") + currentWebroot
);
} else {
return currentWebroot;
}
}
function Mod() {} function Mod() {}
@ -50,6 +63,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
configJSON = configJSONS; configJSON = configJSONS;
} }
var detectedWwwroot = normalizedWebrootSupported ? normalizeWebroot(configJSON.wwwroot) : process.cwd();
function checkIfThereIsA401Rule() { function checkIfThereIsA401Rule() {
var actually401 = false; var actually401 = false;
@ -254,10 +269,10 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
nEnv["SERVER_ADMIN"] = configJSON.serverAdministratorEmail; nEnv["SERVER_ADMIN"] = configJSON.serverAdministratorEmail;
} }
nEnv["SERVER_NAME"] = req.headers.host; nEnv["SERVER_NAME"] = req.headers.host;
nEnv["DOCUMENT_ROOT"] = process.cwd(); nEnv["DOCUMENT_ROOT"] = detectedWwwroot;
nEnv["SCRIPT_NAME"] = scgiConf.path; nEnv["SCRIPT_NAME"] = scgiConf.path;
nEnv["PATH_INFO"] = decodeURIComponent(b); nEnv["PATH_INFO"] = decodeURIComponent(b);
nEnv["PATH_TRANSLATED"] = b ? ((process.cwd() + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : ""; nEnv["PATH_TRANSLATED"] = b ? ((detectedWwwroot + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : "";
nEnv["REQUEST_METHOD"] = req.method; nEnv["REQUEST_METHOD"] = req.method;
nEnv["SCGI"] = "1"; nEnv["SCGI"] = "1";
nEnv["REQUEST_URI"] = (!origHref || origHref == href) ? req.url : (origHref + (uobject.search ? ((uobject.search[0] == "?" ? "" : "?") + uobject.search) : "")); nEnv["REQUEST_URI"] = (!origHref || origHref == href) ? req.url : (origHref + (uobject.search ? ((uobject.search[0] == "?" ? "" : "?") + uobject.search) : ""));
@ -351,7 +366,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e
callServerError(500, "OrangeCircle/" + version, ex); callServerError(500, "OrangeCircle/" + version, ex);
} }
} }
} else if ((href == "/orangecircle-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/orangecircle-config.json")) && path.normalize(__dirname + "/../../..") == process.cwd()) { } else if ((href == "/orangecircle-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/orangecircle-config.json")) && path.normalize(__dirname + "/../../..") == detectedWwwroot) {
if (!callServerError) { if (!callServerError) {
res.writeHead(200, "OK", { res.writeHead(200, "OK", {
"Content-Type": "application/json", "Content-Type": "application/json",