Extract file existance check.

pull/468/head
Chad Weider 2012-02-06 23:05:50 -08:00
parent dcc0740621
commit e33c5a3aac
1 changed files with 18 additions and 9 deletions

View File

@ -64,16 +64,11 @@ exports.minifyJS = function(req, res, next)
res.setHeader('cache-control', 'max-age=' + server.maxAge);
}
fs.stat(JS_DIR + filename, function (error, stats) {
fileExists(filename, function (error, exists) {
if (error) {
if (error.code == "ENOENT") {
res.writeHead(404, {});
res.end();
} else {
res.writeHead(500, {});
res.end();
}
} else if (!stats.isFile()) {
res.writeHead(500, {});
res.end();
} else if (!exists) {
res.writeHead(404, {});
res.end();
} else if (new Date(req.headers['if-modified-since']) >= date) {
@ -236,6 +231,20 @@ function getFile(filename, callback) {
}
}
function fileExists(filename, callback) {
fs.stat(JS_DIR + filename, function (error, stats) {
if (error) {
if (error.code == "ENOENT") {
callback(undefined, false);
} else {
callback(error, undefined);
}
} else {
callback(undefined, stats.isFile());
}
})
}
function tarCode(jsFiles, write, callback) {
write('require.define({');
var initialEntry = true;