You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
const HttpsProxyAgent = require('https-proxy-agent');
|
|
const isDocker = require('is-docker');
|
|
|
|
/*
|
|
* 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
|
|
*/
|
|
|
|
console.log('ISDOCKER? = ' + isDocker());
|
|
|
|
let hostname;
|
|
|
|
if (isDocker()) {
|
|
hostname = 'backend';
|
|
} else {
|
|
hostname = 'localhost';
|
|
}
|
|
|
|
console.log(hostname);
|
|
|
|
const proxyConfig = [
|
|
{
|
|
context: '/api',
|
|
pathRewrite: { '^/api': '' },
|
|
target: 'http://' + hostname + ':3000',
|
|
changeOrigin: true,
|
|
secure: false
|
|
}
|
|
];
|
|
|
|
/*
|
|
* 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);
|
|
|