Skip to content

Commit 4568734

Browse files
authored
Merge pull request #139 from OpenAPITools/issue-130
fix(#130): add proxy support
2 parents c694156 + c9ff828 commit 4568734

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
import {HttpModule, Inject, Module, OnApplicationBootstrap} from '@nestjs/common';
1+
import { HttpModule, Inject, Module, OnApplicationBootstrap } from '@nestjs/common';
2+
import { AxiosProxyConfig } from 'axios';
3+
import { Command } from 'commander';
4+
import * as url from 'url';
25

3-
import {COMMANDER_PROGRAM, LOGGER} from './constants';
4-
import {Command} from 'commander';
5-
import {VersionManagerController} from './controllers/version-manager.controller';
6-
import {ConfigService, GeneratorService, PassTroughService, UIService, VersionManagerService} from './services';
6+
import { COMMANDER_PROGRAM, LOGGER } from './constants';
7+
import { VersionManagerController } from './controllers/version-manager.controller';
8+
import { ConfigService, GeneratorService, PassTroughService, UIService, VersionManagerService } from './services';
9+
10+
let proxyConfig: AxiosProxyConfig;
11+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
12+
13+
if (proxyUrl) {
14+
const proxy = url.parse(proxyUrl);
15+
const proxyAuth = proxy.auth && proxy.auth.split(':');
16+
17+
proxyConfig = {
18+
host: proxy.hostname,
19+
port: parseInt(proxy.port, 10),
20+
auth: proxyAuth && { username: proxyAuth[0], password: proxyAuth[1] },
21+
protocol: proxy.protocol.replace(':', '')
22+
};
23+
}
724

825
@Module({
9-
imports: [HttpModule],
26+
imports: [HttpModule.register({proxy: proxyConfig})],
1027
controllers: [
11-
VersionManagerController,
28+
VersionManagerController
1229
],
1330
providers: [
1431
UIService,
@@ -20,31 +37,31 @@ import {ConfigService, GeneratorService, PassTroughService, UIService, VersionMa
2037
provide: COMMANDER_PROGRAM,
2138
useValue: new Command('openapi-generator-cli').helpOption(false).usage('<command> [<args>]')
2239
},
23-
{provide: LOGGER, useValue: console},
24-
],
40+
{ provide: LOGGER, useValue: console }
41+
]
2542
})
2643
export class AppModule implements OnApplicationBootstrap {
2744

2845
constructor(
2946
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
3047
private readonly versionManager: VersionManagerService,
31-
private readonly passTroughService: PassTroughService,
48+
private readonly passTroughService: PassTroughService
3249
) {
3350
}
3451

3552
onApplicationBootstrap = async () => {
3653

37-
let selectedVersion = this.versionManager.getSelectedVersion()
54+
let selectedVersion = this.versionManager.getSelectedVersion();
3855

3956
if (!selectedVersion) {
40-
const [{version}] = await this.versionManager.search(['latest']).toPromise()
41-
await this.versionManager.setSelectedVersion(version)
42-
selectedVersion = version
57+
const [{ version }] = await this.versionManager.search(['latest']).toPromise();
58+
await this.versionManager.setSelectedVersion(version);
59+
selectedVersion = version;
4360
}
4461

45-
await this.versionManager.downloadIfNeeded(selectedVersion)
46-
await this.passTroughService.init()
47-
this.program.parse(process.argv)
62+
await this.versionManager.downloadIfNeeded(selectedVersion);
63+
await this.passTroughService.init();
64+
this.program.parse(process.argv);
4865

4966
};
5067

0 commit comments

Comments
 (0)