-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.conf.js
59 lines (53 loc) · 1.5 KB
/
proxy.conf.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const HttpsProxyAgent = require('https-proxy-agent');
/*
* API proxy configuration.
* This allows you to proxy HTTP request like `http.get('/api/stuff')` to another server/port.
* This is especially useful during app development to avoid CORS issues while running a local server.
* For more details and options, see https://angular.io/guide/build#using-corporate-proxy
*/
const proxyConfig = [
{
context: '/api0',
pathRewrite: { '^/api': '' },
target: 'https://api.chucknorris.io',
changeOrigin: true,
secure: false
},
{
context: '/api1',
target: 'http://localhost:10060',
pathRewrite: {'^/api1' : ''}
},
{
context: '/api2',
target: 'http://localhost:10070',
pathRewrite: {'^/api2' : ''}
},
{
context: '/api3',
target: 'http://34.121.92.254:10060',
pathRewrite: {'^/api3' : ''}
},
{
context: '/api4',
target: 'http://34.125.56.61:3000',
pathRewrite: {'^/api4' : ''}
}
];
/*
* Configures a corporate proxy agent for the API proxy if needed.
*/
function setupForCorporateProxy(proxyConfig) {
if (!Array.isArray(proxyConfig)) {
proxyConfig = [proxyConfig];
}
const proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
let agent = null;
if (proxyServer) {
console.log(`Using corporate proxy server: ${proxyServer}`);
agent = new HttpsProxyAgent(proxyServer);
proxyConfig.forEach(entry => { entry.agent = agent; });
}
return proxyConfig;
}
module.exports = setupForCorporateProxy(proxyConfig);