From d9f84677f8a34e1d61b625d428a8b02c396974a2 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 8 Aug 2014 05:58:25 +0400 Subject: [PATCH] fix tests broken by webui --- lib/index.js | 18 ++++++++---------- lib/local-storage.js | 7 +++++-- lib/search.js | 4 ++-- lib/storage.js | 14 +++++++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9931d399e..2af51993d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -65,11 +65,9 @@ module.exports = function(config_hash) { app.set('env', process.env.NODE_ENV || 'production') function error_reporting_middleware(req, res, next) { - var calls = 0 res.report_error = res.report_error || function(err) { - calls++ if (err.status && err.status >= 400 && err.status < 600) { - if (calls == 1) { + if (!res.headersSent && !res.headerSent) { res.status(err.status) res.send({error: err.message || 'unknown error'}) } @@ -78,7 +76,7 @@ module.exports = function(config_hash) { if (!res.status || !res.send) { Logger.logger.error('this is an error in express.js, please report this') res.destroy() - } else if (calls == 1) { + } else if (!res.headersSent && !res.headerSent) { res.status(500) res.send({error: 'internal server error'}) } else { @@ -256,8 +254,8 @@ module.exports = function(config_hash) { }) // Static - app.get('/-/static/:file', function(req, res, next) { - var file = __dirname + '/static/' + req.params.file; + app.get('/-/static/:filename', function(req, res, next) { + var file = __dirname + '/static/' + req.params.filename fs.exists(file, function(exists) { if(exists) { res.sendfile(file); @@ -274,8 +272,8 @@ module.exports = function(config_hash) { }); // Search - app.get('/-/search/:query', function(req, res, next) { - var results = search.query(req.params.query), + app.get('/-/search/:anything', function(req, res, next) { + var results = search.query(req.params.anything), packages = []; var getData = function(i) { @@ -308,8 +306,8 @@ module.exports = function(config_hash) { } }); - app.get('/-/readme/:name/:version', function(req, res, next) { - storage.get_readme(req.params.name, req.params.version, function(readme) { + app.get('/-/readme/:package/:version', function(req, res, next) { + storage.get_readme(req.params.package, req.params.version, function(readme) { res.send(marked(readme)); }); }); diff --git a/lib/local-storage.js b/lib/local-storage.js index 2fe988bc8..0f93a4731 100644 --- a/lib/local-storage.js +++ b/lib/local-storage.js @@ -62,8 +62,11 @@ Storage.prototype.add_package = function(name, info, callback) { })) } - search.add(info.versions[info['dist-tags'].latest]); - localList.add(name); + var latest = info['dist-tags'].latest + if (latest && info.versions[latest]) { + search.add(info.versions[latest]) + } + localList.add(name) callback() }) diff --git a/lib/search.js b/lib/search.js index b142971f1..82bd27122 100644 --- a/lib/search.js +++ b/lib/search.js @@ -19,7 +19,7 @@ Search.prototype = { id: package.name, name: package.name, description: package.description, - author: package._npmUser.name + author: package._npmUser ? package._npmUser.name : '???' }); }, remove: function(name) { @@ -43,4 +43,4 @@ Search.prototype = { } }; -module.exports = new Search(); \ No newline at end of file +module.exports = new Search(); diff --git a/lib/storage.js b/lib/storage.js index b62ba186f..be340cfe9 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -424,14 +424,14 @@ Storage.prototype.get_local = function(callback) { var getPackage = function(i) { self.get_package(locals[i], function(err, info) { - var latest = info['dist-tags'].latest; - - packages.push(info.versions[latest]); - - if(err || i >= locals.length - 1) { - callback(err, packages); + if (!err) { + var latest = info['dist-tags'].latest; + packages.push(info.versions[latest]); } - else { + + if (i >= locals.length - 1) { + callback(null, packages); + } else { getPackage(i + 1); } });