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 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();
|
||||
}
|
||||
|
|
Reference in a new issue