-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (28 loc) · 916 Bytes
/
index.js
File metadata and controls
31 lines (28 loc) · 916 Bytes
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
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
if(process.argv[2]){
var target = process.argv[2];
var port = process.argv[3] || 5050;
console.log("Target:",target);
var proxy = httpProxy.createProxyServer({});
proxy.on('proxyRes', (proxyRes, req, res) => {
res.setHeader('access-control-allow-origin',"*");
res.setHeader('access-control-max-age', 60 * 60 * 24 * 30);
if (req.method === 'OPTIONS') {
res.send(200);
res.end();
}
});
var server = http.createServer(function(req, res) {
proxy.web(req, res, {
target: target
});
});
console.log(`listening on port ${port}`)
server.listen(port);
}else{
console.log("Target url is missing, set target like: node indexjs http://<targethost>:<port>");
}