1
0
Fork 0
forked from svrjs/svrjs

Fix .dirimages directory returning 500 error, if it is not present in the web root

This commit is contained in:
Dorian Niemiec 2024-04-13 11:08:48 +02:00
parent 31c2a060ce
commit 4820db0160

19
svr.js
View file

@ -3491,18 +3491,12 @@ if (!cluster.isPrimary) {
var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1); var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1);
var readFrom = "./" + pth; var readFrom = "./" + pth;
var dirImagesMissing = false;
fs.stat(readFrom, function (err, stats) { fs.stat(readFrom, function (err, stats) {
if (err) { if (err) {
if (err.code == "ENOENT") { if (err.code == "ENOENT") {
if (__dirname != process.cwd() && pth.match(/^\.dirimages\/(?:(?!\.png$).)+\.png$/)) { if (__dirname != process.cwd() && pth.match(/^\.dirimages\/(?:(?!\.png$).)+\.png$/)) {
stats = { dirImagesMissing = true;
isDirectory: function isDirectory() {
return false;
},
isFile: function isFile() {
return true;
}
};
readFrom = __dirname + "/" + pth; readFrom = __dirname + "/" + pth;
} else { } else {
callServerError(404); callServerError(404);
@ -3566,6 +3560,15 @@ if (!cluster.isPrimary) {
properDirectoryListingAndStaticFileServe(); properDirectoryListingAndStaticFileServe();
} }
}); });
} else if (dirImagesMissing) {
fs.stat(readFrom, function (e, s) {
if (e || !s.isFile()) {
properDirectoryListingAndStaticFileServe();
} else {
stats = s;
properDirectoryListingAndStaticFileServe();
}
});
} else { } else {
properDirectoryListingAndStaticFileServe(); properDirectoryListingAndStaticFileServe();
} }