Skip to content

Commit 7787f07

Browse files
authored
fix(app): configure http with proxy url if present in environment (#762)
* chore(deps): install `https-proxy-agent` as dependency * fix(app): configure http agent with proxy url if present in environment Fixes ##714
1 parent fb01b0b commit 7787f07

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed
Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
import {Inject, Module, OnApplicationBootstrap} from '@nestjs/common';
2-
import {HttpModule} from '@nestjs/axios';
3-
import {Command} from 'commander';
1+
import { Inject, Module, OnApplicationBootstrap } from '@nestjs/common';
2+
import { HttpModule, HttpModuleOptions } from '@nestjs/axios';
3+
import { Command } from 'commander';
44

5-
import {COMMANDER_PROGRAM, LOGGER} from './constants';
6-
import {VersionManagerController} from './controllers/version-manager.controller';
7-
import {ConfigService, GeneratorService, PassThroughService, UIService, VersionManagerService} from './services';
5+
import { COMMANDER_PROGRAM, LOGGER } from './constants';
6+
import { VersionManagerController } from './controllers/version-manager.controller';
7+
import {
8+
ConfigService,
9+
GeneratorService,
10+
PassThroughService,
11+
UIService,
12+
VersionManagerService,
13+
} from './services';
14+
import { HttpsProxyAgent } from 'https-proxy-agent';
15+
16+
const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
17+
const httpModuleConfig: HttpModuleOptions = {};
18+
19+
if (proxyUrl) {
20+
httpModuleConfig.proxy = false;
21+
httpModuleConfig.httpsAgent = new HttpsProxyAgent(proxyUrl);
22+
}
823

924
@Module({
10-
imports: [HttpModule],
11-
controllers: [
12-
VersionManagerController
25+
imports: [
26+
HttpModule.register({
27+
...httpModuleConfig,
28+
}),
1329
],
30+
controllers: [VersionManagerController],
1431
providers: [
1532
UIService,
1633
ConfigService,
@@ -19,34 +36,37 @@ import {ConfigService, GeneratorService, PassThroughService, UIService, VersionM
1936
VersionManagerService,
2037
{
2138
provide: COMMANDER_PROGRAM,
22-
useValue: new Command('openapi-generator-cli').helpOption(false).usage('<command> [<args>]').option( '--openapitools <openapitools.json>', 'Use the specified openapi-generator-cli configuration file')
39+
useValue: new Command('openapi-generator-cli')
40+
.helpOption(false)
41+
.usage('<command> [<args>]')
42+
.option(
43+
'--openapitools <openapitools.json>',
44+
'Use the specified openapi-generator-cli configuration file',
45+
),
2346
},
24-
{provide: LOGGER, useValue: console}
25-
]
47+
{ provide: LOGGER, useValue: console },
48+
],
2649
})
2750
export class AppModule implements OnApplicationBootstrap {
28-
2951
constructor(
3052
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
3153
private readonly versionManager: VersionManagerService,
32-
private readonly passThroughService: PassThroughService
33-
) {
34-
}
54+
private readonly passThroughService: PassThroughService,
55+
) {}
3556

3657
onApplicationBootstrap = async () => {
37-
3858
let selectedVersion = this.versionManager.getSelectedVersion();
3959

4060
if (!selectedVersion) {
41-
const [{version}] = await this.versionManager.search(['latest']).toPromise();
61+
const [{ version }] = await this.versionManager
62+
.search(['latest'])
63+
.toPromise();
4264
await this.versionManager.setSelectedVersion(version);
4365
selectedVersion = version;
4466
}
4567

4668
await this.versionManager.downloadIfNeeded(selectedVersion);
4769
await this.passThroughService.init();
4870
this.program.parse(process.argv);
49-
5071
};
51-
5272
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"concurrently": "6.5.1",
9292
"console.table": "0.10.0",
9393
"fs-extra": "10.1.0",
94+
"https-proxy-agent": "^7.0.4",
9495
"inquirer": "8.2.6",
9596
"jsonpath": "1.1.1",
9697
"lodash": "4.17.21",

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5938,6 +5938,14 @@ https-proxy-agent@^7.0.0, https-proxy-agent@^7.0.1:
59385938
agent-base "^7.0.2"
59395939
debug "4"
59405940

5941+
https-proxy-agent@^7.0.4:
5942+
version "7.0.4"
5943+
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz#8e97b841a029ad8ddc8731f26595bad868cb4168"
5944+
integrity sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==
5945+
dependencies:
5946+
agent-base "^7.0.2"
5947+
debug "4"
5948+
59415949
human-signals@^2.1.0:
59425950
version "2.1.0"
59435951
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"

0 commit comments

Comments
 (0)