Permalink
Browse files

Extract file existance check.

  • Loading branch information...
1 parent dcc0740 commit e33c5a3aacdcd536176d87502bf5976d8764efcf @cweider committed Feb 7, 2012
Showing with 18 additions and 9 deletions.
  1. +18 −9 node/utils/Minify.js
View
@@ -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;

0 comments on commit e33c5a3

Please sign in to comment.