Skip to content

Commit a4ef67e

Browse files
committed
fix(app): configure http agent with proxy url if present in environment
Fixes #OpenAPITools#714
1 parent 8b56098 commit a4ef67e

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-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
}

0 commit comments

Comments
 (0)