From a09e208b0a5683c923ab164d2418ea96beede29d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 29 Jan 2012 12:54:12 -0800 Subject: [PATCH] Return 404's. --- node/utils/Minify.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 18a6609b..93bb263f 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -57,13 +57,7 @@ exports.minifyJS = function(req, res, next) } else { // Not in tar list, but try anyways, if it fails, pass to `next`. jsFiles = [jsFilename]; - fs.stat(JS_DIR + jsFilename, function (error, stats) { - if (error || !stats.isFile()) { - next(); - } else { - _handle(req, res, jsFilename, jsFiles); - } - }); + _handle(req, res, jsFilename, jsFiles); } } @@ -75,14 +69,29 @@ function _handle(req, res, jsFilename, jsFiles) { res.setHeader('last-modified', date.toUTCString()); res.setHeader('date', (new Date()).toUTCString()); - if (new Date(req.headers['if-modified-since']) >= date) { - res.writeHead(304, {}); - res.end(); - } else if (settings.minify) { - respondMinified(); - } else { - respondRaw(); - } + fs.stat(JS_DIR + jsFiles[0], function (error, stats) { + if (error) { + if (error.code == "ENOENT") { + res.writeHead(404, {}); + res.end(); + } else { + res.writeHead(500, {}); + res.end(); + } + } else if (!stats.isFile()) { + res.writeHead(404, {}); + res.end(); + } else if (new Date(req.headers['if-modified-since']) >= date) { + res.writeHead(304, {}); + res.end(); + } else { + if (settings.minify) { + respondMinified(); + } else { + respondRaw(); + } + } + }); }); function respondMinified()