forked from hughsk/npm-quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 1019 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var http = require('http')
, url = require('url')
, request = require('request');
http.createServer(function(req, res) {
var file = url.parse(req.url).path;
if (!file.match(/\.tgz$/g)) {
return request.get('https://registry.npmjs.org' + req.url, function(err, response, body) {
var body = JSON.parse(body)
, versions = body.versions
, name = body.name;
console.log(require('util').inspect(body, null, null, null));
if (body.dist && body.dist.tarball) body.dist.tarball = body.dist.tarball
.replace(/http(s)?\:\/\/registry.npmjs.org\/\-\//,
'https://registry.npmjs.org/' + name + '/-/'
);
if (versions) Object.keys(versions).forEach(function(version) {
versions[version].dist.tarball = versions[version].dist.tarball
.replace(/http(s)?\:\/\/registry.npmjs.org\/\-\//,
'https://registry.npmjs.org/' + name + '/-/'
);
});
res.end(JSON.stringify(body));
});
}
request.get('https://registry.npmjs.org' + req.url).pipe(res);
}).listen(8080);