Skip to content

Commit 69c9dc5

Browse files
committed
fix(http): use proxy-agent that respect env variables and "no-proxy"-env
Related to OpenAPITools#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.
1 parent 44e7e33 commit 69c9dc5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

apps/generator-cli/src/app/app.module.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ import {
1111
UIService,
1212
VersionManagerService,
1313
} from './services';
14-
import { HttpsProxyAgent } from 'https-proxy-agent';
14+
import { ProxyAgent } from 'proxy-agent';
1515

16-
const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
16+
const hasHttpProxyEnvs = process.env.HTTP_PROXY || process.env.http_proxy;
17+
const hasHttpsProxyEnvs = process.env.HTTPS_PROXY || process.env.https_proxy;
1718
const httpModuleConfig: HttpModuleOptions = {};
1819

19-
if (proxyUrl) {
20+
const proxyAgent = new ProxyAgent();
21+
22+
if (hasHttpProxyEnvs) {
23+
httpModuleConfig.proxy = false;
24+
httpModuleConfig.httpAgent = proxyAgent;
25+
}
26+
27+
if (hasHttpsProxyEnvs) {
2028
httpModuleConfig.proxy = false;
21-
httpModuleConfig.httpsAgent = new HttpsProxyAgent(proxyUrl);
29+
httpModuleConfig.httpsAgent = proxyAgent;
2230
}
2331

2432
@Module({

0 commit comments

Comments
 (0)