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(); }