Skip to content

Commit 9079344

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

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed
Lines changed: 35 additions & 19 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,33 @@ 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>]')
39+
useValue: new Command('openapi-generator-cli')
40+
.helpOption(false)
41+
.usage('<command> [<args>]'),
2342
},
24-
{provide: LOGGER, useValue: console}
25-
]
43+
{ provide: LOGGER, useValue: console },
44+
],
2645
})
2746
export class AppModule implements OnApplicationBootstrap {
28-
2947
constructor(
3048
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
3149
private readonly versionManager: VersionManagerService,
3250
private readonly passThroughService: PassThroughService
33-
) {
34-
}
51+
) {}
3552

3653
onApplicationBootstrap = async () => {
37-
3854
let selectedVersion = this.versionManager.getSelectedVersion();
3955

4056
if (!selectedVersion) {
41-
const [{version}] = await this.versionManager.search(['latest']).toPromise();
57+
const [{ version }] = await this.versionManager
58+
.search(['latest'])
59+
.toPromise();
4260
await this.versionManager.setSelectedVersion(version);
4361
selectedVersion = version;
4462
}
4563

4664
await this.versionManager.downloadIfNeeded(selectedVersion);
4765
await this.passThroughService.init();
4866
this.program.parse(process.argv);
49-
5067
};
51-
5268
}

0 commit comments

Comments
 (0)