Skip to content

Commit

Permalink
fix(http): use proxy agent that respect env variables and no proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jontze committed Apr 22, 2024
1 parent c7caf87 commit 7e31c2e
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 7e31c2e

Please sign in to comment.