From 96ee77d85b9e0880c7986894de16c546f114b3d2 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:05:27 -0800 Subject: [PATCH 1/8] Check error not stats. --- node/utils/caching_middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index 809bb210f..2cdb2dfcf 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -53,7 +53,7 @@ CachingMiddleware.prototype = new function () { fs.stat(CACHE_DIR + 'minified_' + cacheKey, function (error, stats) { var modifiedSince = (req.headers['if-modified-since'] && new Date(req.headers['if-modified-since'])); - var lastModifiedCache = stats && stats.mtime; + var lastModifiedCache = !error && stats.mtime; if (lastModifiedCache) { req.headers['if-modified-since'] = lastModifiedCache.toUTCString(); } else { From 24a26953a7c2e69cd365270a464bd4d347f70771 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:06:30 -0800 Subject: [PATCH 2/8] Account for undefined argument. --- node/utils/caching_middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index 2cdb2dfcf..8c51f662f 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -87,7 +87,7 @@ CachingMiddleware.prototype = new function () { // Update cache var buffer = ''; - Object.keys(headers).forEach(function (key) { + Object.keys(headers || {}).forEach(function (key) { res.setHeader(key, headers[key]); }); headers = _headers; From 118e7928b96f771127775486b2a84f3cd8cba824 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:08:03 -0800 Subject: [PATCH 3/8] Headers should only be set after file is written. --- node/utils/caching_middleware.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index 8c51f662f..b0da22dc7 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -91,7 +91,6 @@ CachingMiddleware.prototype = new function () { res.setHeader(key, headers[key]); }); headers = _headers; - responseCache[cacheKey] = {statusCode: status, headers: headers}; old_res.write = res.write; old_res.end = res.end; @@ -118,7 +117,10 @@ CachingMiddleware.prototype = new function () { } }); } - ], respond); + ], function () { + responseCache[cacheKey] = {statusCode: status, headers: headers}; + respond(); + }); }; } else if (status == 304) { // Nothing new changed from the cached version. From a7c009d0c9bb711d11ee20b998ffdd853a4d5c47 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:09:33 -0800 Subject: [PATCH 4/8] Status code should not be assumed. --- node/utils/caching_middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index b0da22dc7..f25059b88 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -164,7 +164,7 @@ CachingMiddleware.prototype = new function () { res.writeHead(statusCode, headers); util.pump(readStream, res); } else { - res.writeHead(200, headers); + res.writeHead(statusCode, headers); res.end(); } } From 45ba5d60dc9d2e48f491cfcc9e30ceadb129facc Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:13:10 -0800 Subject: [PATCH 5/8] Windows does not like IP addresses of 0.0.0.0. --- node/server.js | 2 +- node/utils/Minify.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/server.js b/node/server.js index 8b0ab2f59..c5377d81b 100644 --- a/node/server.js +++ b/node/server.js @@ -154,7 +154,7 @@ async.waterfall([ // CommonJS loader on the client-side. var jsServer = new (Yajsml.Server)({ rootPath: 'minified/' - , rootURI: 'http://' + settings.ip + ":" + settings.port + '/static/js/' + , rootURI: 'http://localhost:' + settings.port + '/static/js/' }); var StaticAssociator = Yajsml.associators.StaticAssociator; var associations = diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 00e1ce224..04371851c 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -148,7 +148,7 @@ function getAceFile(callback) { var filename = item.match(/"([^"]*)"/)[1]; var request = require('request'); - var baseURI = 'http://' + settings.ip + ":" + settings.port + var baseURI = 'http://localhost:' + settings.port request(baseURI + path.normalize(path.join('/static/', filename)), function (error, response, body) { if (!error && response.statusCode == 200) { From 45b7cafca491c01fb0e76ca5e39a7d3ed401996e Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 18:29:23 -0800 Subject: [PATCH 6/8] Don't let filenames be changed to Windows' backslash-notation. --- node/utils/Minify.js | 1 + 1 file changed, 1 insertion(+) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 04371851c..98eb6f926 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -57,6 +57,7 @@ exports.minify = function(req, res, next) filename = path.normalize(path.join(ROOT_DIR, filename)); if (filename.indexOf(ROOT_DIR) == 0) { filename = filename.slice(ROOT_DIR.length); + filename = filename.replace(/\\/g, '/'); // Windows (safe generally?) } else { res.writeHead(404, {}); res.end(); From 82652dffdae5ab593780f12447745a984e1410b3 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 19:00:27 -0800 Subject: [PATCH 7/8] Revert "Add a hack to prevent redirect of requests for `/static/js/pad` to `/static/js/pad.js`." This reverts commit af4bd5ca65637dc660a2ccda9f2454180f38f4d3. --- node/utils/Minify.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 98eb6f926..a49195a7b 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -35,10 +35,9 @@ var TAR_PATH = path.join(__dirname, 'tar.json'); var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8')); // Rewrite tar to include modules with no extensions and proper rooted paths. -// HACK: Also use non-extension name so redirects are not encountered. exports.tar = {}; for (var key in tar) { - exports.tar['/' + key.replace(/\.js$/, '')] = + exports.tar['/' + key] = tar[key].map(function (p) {return '/' + p}).concat( tar[key].map(function (p) {return '/' + p.replace(/\.js$/, '')}) ); From 07823ddf26a14c9ec56ff62973db5b1647843ef1 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 19:40:10 -0800 Subject: [PATCH 8/8] Update to yajsml with more windows support. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3231eb6ca..01eb8e96a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "name": "Robin Buse" } ], "dependencies" : { - "yajsml" : "1.1.1", + "yajsml" : "1.1.2", "request" : "2.9.100", "require-kernel" : "1.0.3", "socket.io" : "0.8.7",