From 7e31c2eae8ec91b65b18895585c94c3078aa926e Mon Sep 17 00:00:00 2001 From: Jontze Date: Mon, 22 Apr 2024 10:40:50 +0200 Subject: [PATCH] fix(http): use proxy agent that respect env variables and no proxy --- apps/generator-cli/src/app/app.module.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/generator-cli/src/app/app.module.ts b/apps/generator-cli/src/app/app.module.ts index f67633860..87cd6fe51 100644 --- a/apps/generator-cli/src/app/app.module.ts +++ b/apps/generator-cli/src/app/app.module.ts @@ -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({