From 4820db01600f3227ffcc5bd107415bba42d86a36 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 13 Apr 2024 11:08:48 +0200 Subject: [PATCH] Fix .dirimages directory returning 500 error, if it is not present in the web root --- svr.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/svr.js b/svr.js index 10a47d2..ae8bc54 100644 --- a/svr.js +++ b/svr.js @@ -3491,18 +3491,12 @@ if (!cluster.isPrimary) { var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1); var readFrom = "./" + pth; + var dirImagesMissing = false; fs.stat(readFrom, function (err, stats) { if (err) { if (err.code == "ENOENT") { if (__dirname != process.cwd() && pth.match(/^\.dirimages\/(?:(?!\.png$).)+\.png$/)) { - stats = { - isDirectory: function isDirectory() { - return false; - }, - isFile: function isFile() { - return true; - } - }; + dirImagesMissing = true; readFrom = __dirname + "/" + pth; } else { callServerError(404); @@ -3566,6 +3560,15 @@ if (!cluster.isPrimary) { properDirectoryListingAndStaticFileServe(); } }); + } else if (dirImagesMissing) { + fs.stat(readFrom, function (e, s) { + if (e || !s.isFile()) { + properDirectoryListingAndStaticFileServe(); + } else { + stats = s; + properDirectoryListingAndStaticFileServe(); + } + }); } else { properDirectoryListingAndStaticFileServe(); }