-
-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathapp.module.ts
More file actions
72 lines (65 loc) · 2.06 KB
/
app.module.ts
File metadata and controls
72 lines (65 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Inject, Module, OnApplicationBootstrap } from '@nestjs/common';
import { HttpModule, HttpModuleOptions } from '@nestjs/axios';
import { Command } from 'commander';
import { COMMANDER_PROGRAM, LOGGER } from './constants';
import { VersionManagerController } from './controllers/version-manager.controller';
import {
ConfigService,
GeneratorService,
PassThroughService,
UIService,
VersionManagerService,
} from './services';
import { HttpsProxyAgent } from 'https-proxy-agent';
const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const httpModuleConfig: HttpModuleOptions = {};
if (proxyUrl) {
httpModuleConfig.proxy = false;
httpModuleConfig.httpsAgent = new HttpsProxyAgent(proxyUrl);
}
@Module({
imports: [
HttpModule.register({
...httpModuleConfig,
}),
],
controllers: [VersionManagerController],
providers: [
UIService,
ConfigService,
GeneratorService,
PassThroughService,
VersionManagerService,
{
provide: COMMANDER_PROGRAM,
useValue: new Command('openapi-generator-cli')
.helpOption(false)
.usage('<command> [<args>]')
.option(
'--openapitools <openapitools.json>',
'Use the specified openapi-generator-cli configuration file',
),
},
{ provide: LOGGER, useValue: console },
],
})
export class AppModule implements OnApplicationBootstrap {
constructor(
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
private readonly versionManager: VersionManagerService,
private readonly passThroughService: PassThroughService,
) {}
onApplicationBootstrap = async () => {
let selectedVersion = this.versionManager.getSelectedVersion();
if (!selectedVersion) {
const [{ version }] = await this.versionManager
.search(['latest'])
.toPromise();
await this.versionManager.setSelectedVersion(version);
selectedVersion = version;
}
await this.versionManager.downloadIfNeeded(selectedVersion);
await this.passThroughService.init();
this.program.parse(process.argv);
};
}