-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend proxy behind corporate proxy does not work #4041
Comments
I experimented a little and found that the proxy config could actually be a JS file, so I added my old fix to have this in 'use strict';
const HttpsProxyAgent = require('https-proxy-agent');
const proxyConfig = [
{
context: '/api',
pathRewrite: {'^/api': ''},
target: 'http://api.icndb.com',
changeOrigin: true
}
];
function setupForCorporateProxy(proxyConfig) {
if (!Array.isArray(proxyConfig)) {
proxyConfig = [proxyConfig];
}
const proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
let agent = null;
if (proxyServer) {
agent = new HttpsProxyAgent(proxyServer);
console.log(`Using corporate proxy server: ${proxyServer}`);
proxyConfig.forEach(entry => { entry.agent = agent; });
}
return proxyConfig;
}
module.exports = setupForCorporateProxy(proxyConfig); So far so good, everything works as expected :) Maybe this example could be added to the documentation? Working behind a corporate proxy is really a pain in the a** to configure... |
@sinedied Any chance you could raise a PR to update docs? |
@mmrath sure, I'll do it as soon as I have some free time |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
Repro steps.
I work behind a corporate proxy (like many of us), and because of this, the backend proxy fails to make the actual http calls because it does not use the corporate proxy.
Here is my
proxy.conf.json
setup:The log given by the failure.
This is the error output in the console:
Mention any other details that might be useful.
With my old gulp-based setup, I was able to easily fix this issue by providing a custom Http Agent to the http-proxy-middleware module. The agent just looks at the
http_proxy
orHTTP_PROXY
environment variable, and setup the corporate proxy if found.I could do the same here if the options were not stored in a JSON file, but a regular js file, maybe that would be the simplest way to fix this issue?
The text was updated successfully, but these errors were encountered: