forked from anvaka/corsregistry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (25 loc) · 766 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
// Where do we listen to incoming connections?
var port = process.env.PORT || 3000;
// Where to proxy requests:
var endpoint = 'https://registry.npmjs.org';
var express = require('express');
var proxy = require('express-http-proxy');
var app = express();
app.use('/*', createProxyRoute());
app.listen(port, function() {
console.log('Registry proxy started at: http://localhost:' + port);
});
function createProxyRoute() {
return proxy(endpoint, {
forwardPath: function(req, res) {
res.set('Access-Control-Allow-Origin', '*');
return req.originalUrl;
}
});
}
function corsOptionsDelegate(req, callback) {
var corsOptions = {
origin: true
};
callback(null, corsOptions); // callback expects two parameters: error and options
}