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..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$/, '')}) ); @@ -57,6 +56,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(); @@ -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) { diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index 809bb210f..f25059b88 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 { @@ -87,11 +87,10 @@ 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; - 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. @@ -162,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(); } } 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",