From 9bc6b3b37e49dc455ba342b9bd397aa731fcdea8 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Mon, 9 Dec 2024 15:48:14 +0100 Subject: [PATCH] chore: release YellowSquare 1.1.4 --- index.js | 26 +++++++++++++++++++++----- mod.info | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 62e6825..308c538 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,20 @@ class ErrorStream extends stream.Writable { } } +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() {} Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, ext, uobject, search, defaultpage, users, page404, head, foot, fd, elseCallback, configJSON, callServerError, getCustomHeaders, origHref, redirect, parsePostData, authUser) { @@ -62,6 +76,8 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e configJSON = configJSONS; } + var detectedWwwroot = normalizedWebrootSupported ? normalizeWebroot(configJSON.wwwroot) : process.cwd(); + function checkIfThereIsA401Rule() { var actually401 = false; @@ -118,7 +134,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e return; } try { - var JSGIApp = require(process.cwd() + "/" + fname); + var JSGIApp = require(detectedWwwroot + "/" + fname); var jsgiResponseObject = {}; if (typeof JSGIApp === "object" && JSGIApp.app) { jsgiResponseObject = JSGIApp.app(jsgiRequestObject); @@ -181,7 +197,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e input: inputStream, scriptName: a, pathInfo: decodeURIComponent(b), - pathTranslated: b ? ((process.cwd() + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : "", + pathTranslated: b ? ((detectedWwwroot + decodeURIComponent(require("os").platform == "win32" ? b.replace(/\//g, "\\") : b)).replace((require("os").platform == "win32" ? /\\\\/g : /\/\//g), (require("os").platform == "win32" ? "\\" : "/"))) : "", scheme: req.socket.encrypted ? "https" : "http", env: {}, jsgi: { @@ -230,11 +246,11 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e jsgiRequestObject.host = pubip.replace(/^::ffff:/i, ""); if (jsgiRequestObject.host.indexOf(":") != -1) jsgiRequestObject.host = "[" + jsgiRequestObject.host + "]"; } - executeJSGI("." + a, req, res, dh, jsgiRequestObject); + executeJSGI(detectedWwwroot + a, req, res, dh, jsgiRequestObject); } if (href.match(new RegExp("^/jsgi-bin(?:$|[?#/])",os.platform() == "win32" ? "i" : ""))) { - fs.stat("." + decodeURIComponent(href), function (err, stats) { + fs.stat(detectedWwwroot + decodeURIComponent(href), function (err, stats) { if (!err) { if (!stats.isFile()) { elseCallback(); @@ -299,7 +315,7 @@ Mod.prototype.callback = function (req, res, serverconsole, responseEnd, href, e if (!a) b = []; else var b = a.split("/"); var isFile = false; - fs.stat(pth, function (err, stats) { + fs.stat(detectedWwwroot + "/" + pth, function (err, stats) { if (!err && stats.isFile()) { cb({ fpth: pth, diff --git a/mod.info b/mod.info index d588fcb..d39277a 100755 --- a/mod.info +++ b/mod.info @@ -1,4 +1,4 @@ { "name": "YellowSquare JSGI engine for SVR.JS", - "version": "1.1.3" + "version": "1.1.4" }