1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/lib/st-proxy.js

42 lines
1002 B
JavaScript
Raw Normal View History

2013-06-08 03:16:28 +02:00
var request = require('request');
2013-06-14 10:34:29 +02:00
var UError = require('./error').UserError;
2013-06-08 03:16:28 +02:00
var URL = require('url');
function Storage(name, config) {
if (!(this instanceof Storage)) return new Storage(config);
this.config = config;
this.name = name;
this.ca;
if (URL.parse(this.config.uplinks[this.name].url).hostname === 'registry.npmjs.org') {
this.ca = require('./npmsslkeys');
}
return this;
}
Storage.prototype.get_package = function(name, callback) {
request({
url: this.config.uplinks[this.name].url + '/' + name,
json: true,
headers: {
'User-Agent': this.config.user_agent,
},
ca: this.ca,
}, function(err, res, body) {
if (err) return callback(err);
2013-06-14 10:34:29 +02:00
if (res.statusCode === 404) {
return callback(new UError({
msg: 'package doesn\'t exist on uplink',
status: 404,
}));
}
2013-06-14 09:56:02 +02:00
if (!(res.statusCode >= 200 && res.statusCode < 300)) {
return callback(new Error('bad status code: ' + res.statusCode));
}
2013-06-08 03:16:28 +02:00
callback(null, body);
});
}
module.exports = Storage;