0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-17 23:45:29 -05:00

improving tags support (read-only for now)

This commit is contained in:
Alex Kocharin 2013-10-02 22:26:20 +04:00
parent 1556ce195a
commit f38a897fa2
2 changed files with 22 additions and 13 deletions

View file

@ -33,7 +33,7 @@ module.exports = function(config_hash) {
app.use(basic_auth(function(user, pass) {
return config.authenticate(user, pass);
}));
app.use(express.bodyParser());
app.use(express.bodyParser({strict: false}));
// TODO: npm DO NOT support compression :(
app.use(express.compress());
@ -66,19 +66,28 @@ module.exports = function(config_hash) {
if (err) return next(err);
info = utils.filter_tarball_urls(info, req, config);
// XXX: in some cases npm calls for /:package and for some cases
// for /:package/:version - should investigate that
if (req.params.version) {
if (info.versions[req.params.version] != null) {
info = info.versions[req.params.version];
} else {
return next(new UError({
status: 404,
msg: 'version not found: ' + req.params.version
}));
var version = req.params.version;
if (!version) {
return res.send(info);
}
if (info.versions[version] != null) {
return res.send(info.versions[version]);
}
if (info['dist-tags'] != null) {
if (info['dist-tags'][version] != null) {
version = info['dist-tags'][version];
if (info.versions[version] != null) {
return res.send(info.versions[version]);
}
}
}
res.send(info);
return next(new UError({
status: 404,
msg: 'version not found: ' + req.params.version
}));
});
});

View file

@ -28,7 +28,7 @@ module.exports.media = function media(expect) {
}
module.exports.expect_json = function expect_json(req, res, next) {
if (typeof(req.body) !== 'object') {
if (typeof(req.body) !== 'object' || req.body === null) {
return next({
status: 400,
msg: 'can\'t parse incoming json',