forked from svrjs/svrjs
Fix .dirimages directory returning 500 error, if it is not present in the web root
This commit is contained in:
parent
31c2a060ce
commit
4820db0160
1 changed files with 11 additions and 8 deletions
19
svr.js
19
svr.js
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue