0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

fix tests broken by webui

This commit is contained in:
Alex Kocharin 2014-08-08 05:58:25 +04:00
parent e1880ce19e
commit d9f84677f8
4 changed files with 22 additions and 21 deletions

View file

@ -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));
});
});

View file

@ -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()
})

View file

@ -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();
module.exports = new Search();

View file

@ -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);
}
});