问题
I'm try run a angular reverse proxy to request a API as if it were localhost, but i'm behind a corporate proxy.
I created a proxy.conf.json file
{
"/api/*": {
"target": "http://104.43.135.128:8000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {"^/api" : ""}
}
}
and i'm run angular with npm start (I modified the package.json)
"start": "ng serve --proxy-config proxy.conf.json",
¿Does anyone know how i canconfigure a corporate proxy in angular?
I have this error.
[HPM] Error occurred while trying to proxy request
回答1:
Have you tried to do what is descibed in the documentation
npm install --save-dev https-proxy-agent
Create proxy.js
var HttpsProxyAgent = require('https-proxy-agent');
var proxyConfig = [{
context: '/api',
target: 'http://104.43.135.128:8000',
secure: false,
changeOrigin: true,
pathRewrite: { "^/api": ""}
}];
function setupForCorporateProxy(proxyConfig) {
var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
if (proxyServer) {
var agent = new HttpsProxyAgent(proxyServer);
console.log('Using corporate proxy server: ' + proxyServer);
proxyConfig.forEach(function(entry) {
entry.agent = agent;
});
}
return proxyConfig;
}
module.exports = setupForCorporateProxy(proxyConfig);
And run angular with npm start
( modify the package.json)
"start": "ng serve --proxy-config proxy.js",
来源:https://stackoverflow.com/questions/52897543/angular-reverse-proxy-behind-a-corporate-proxy