-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.js
42 lines (35 loc) · 1.03 KB
/
proxy.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
34
35
36
37
38
39
40
41
42
var fs = require('fs'),
httpProxy = require('http-proxy');
var proxy = httpProxy.createServer({
ssl: {
key: fs.readFileSync('./key.pem', 'utf8'),
cert: fs.readFileSync('./cert.pem', 'utf8'),
},
target: 'https://dashboard.9spokes.com/api/v1',
secure: false, // Depends on your needs, could be false.
});
proxy.on('proxyRes', function(proxyRes, req, res) {
console.log(
'RAW Response from the target',
JSON.stringify(proxyRes.headers, true, 2)
);
res.setHeader('access-control-allow-origin', '*');
if (req.headers['access-control-request-method']) {
res.setHeader(
'access-control-allow-methods',
req.headers['access-control-request-method']
);
}
if (req.headers['access-control-request-headers']) {
res.setHeader(
'access-control-allow-headers',
req.headers['access-control-request-headers']
);
}
if (req.method === 'OPTIONS') {
console.log('OPTIONS');
res.writeHead(200);
res.end()
}
});
proxy.listen(8000);