Skip to content

Commit

Permalink
fix(http): use proxy-agent that respect env variables and "no-proxy"-env
Browse files Browse the repository at this point in the history
Related to #762

In the linked PR, the proxy config was restored, but it didn't respected
the `NO_PROXY` | `no_proxy` configuration. This commit moved to a
different approach that is working with all common proxy environment
variables.
  • Loading branch information
jontze committed Apr 24, 2024
1 parent 44e7e33 commit 69c9dc5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/generator-cli/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ import {
UIService,
VersionManagerService,
} from './services';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { ProxyAgent } from 'proxy-agent';

const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const hasHttpProxyEnvs = process.env.HTTP_PROXY || process.env.http_proxy;
const hasHttpsProxyEnvs = process.env.HTTPS_PROXY || process.env.https_proxy;
const httpModuleConfig: HttpModuleOptions = {};

if (proxyUrl) {
const proxyAgent = new ProxyAgent();

if (hasHttpProxyEnvs) {
httpModuleConfig.proxy = false;
httpModuleConfig.httpAgent = proxyAgent;
}

if (hasHttpsProxyEnvs) {
httpModuleConfig.proxy = false;
httpModuleConfig.httpsAgent = new HttpsProxyAgent(proxyUrl);
httpModuleConfig.httpsAgent = proxyAgent;
}

@Module({
Expand Down

0 comments on commit 69c9dc5

Please sign in to comment.