forked from zeppelin-next/zeppelin-frontend-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.conf.js
47 lines (43 loc) · 1.01 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
const dotenv = require('dotenv');
const HttpsProxyAgent = require('https-proxy-agent');
dotenv.config();
const proxyConfig = [
{
context: ['/'],
target: 'http://localhost:8080',
secure: false,
changeOrigin: true
},
{
context: '/ws',
target: 'ws://localhost:8080',
secure: false,
ws:true,
changeOrigin: true
}
];
function httpUrlToWSUrl(url) {
return url.replace(/(http)(s)?\:\/\//, "ws$2://");
}
function setupForCorporateProxy(proxyConfig) {
const proxyServer = process.env.SERVER_PROXY;
const httpProxy = process.env.HTTP_PROXY;
if (proxyServer) {
let agent = null;
if (httpProxy) {
agent = new HttpsProxyAgent(httpProxy);
}
proxyConfig.forEach(function(entry) {
if (entry.context === '/ws') {
entry.target = httpUrlToWSUrl(proxyServer)
} else {
entry.target = proxyServer;
}
if (agent) {
entry.agent = agent;
}
});
}
return proxyConfig;
}
module.exports = setupForCorporateProxy(proxyConfig);