Skip to content

Commit

Permalink
Merge pull request #139 from OpenAPITools/issue-130
Browse files Browse the repository at this point in the history
fix(#130): add proxy support
  • Loading branch information
kay-schecker authored Nov 21, 2020
2 parents c694156 + c9ff828 commit 4568734
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions apps/generator-cli/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import {HttpModule, Inject, Module, OnApplicationBootstrap} from '@nestjs/common';
import { HttpModule, Inject, Module, OnApplicationBootstrap } from '@nestjs/common';
import { AxiosProxyConfig } from 'axios';
import { Command } from 'commander';
import * as url from 'url';

import {COMMANDER_PROGRAM, LOGGER} from './constants';
import {Command} from 'commander';
import {VersionManagerController} from './controllers/version-manager.controller';
import {ConfigService, GeneratorService, PassTroughService, UIService, VersionManagerService} from './services';
import { COMMANDER_PROGRAM, LOGGER } from './constants';
import { VersionManagerController } from './controllers/version-manager.controller';
import { ConfigService, GeneratorService, PassTroughService, UIService, VersionManagerService } from './services';

let proxyConfig: AxiosProxyConfig;
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;

if (proxyUrl) {
const proxy = url.parse(proxyUrl);
const proxyAuth = proxy.auth && proxy.auth.split(':');

proxyConfig = {
host: proxy.hostname,
port: parseInt(proxy.port, 10),
auth: proxyAuth && { username: proxyAuth[0], password: proxyAuth[1] },
protocol: proxy.protocol.replace(':', '')
};
}

@Module({
imports: [HttpModule],
imports: [HttpModule.register({proxy: proxyConfig})],
controllers: [
VersionManagerController,
VersionManagerController
],
providers: [
UIService,
Expand All @@ -20,31 +37,31 @@ import {ConfigService, GeneratorService, PassTroughService, UIService, VersionMa
provide: COMMANDER_PROGRAM,
useValue: new Command('openapi-generator-cli').helpOption(false).usage('<command> [<args>]')
},
{provide: LOGGER, useValue: console},
],
{ provide: LOGGER, useValue: console }
]
})
export class AppModule implements OnApplicationBootstrap {

constructor(
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
private readonly versionManager: VersionManagerService,
private readonly passTroughService: PassTroughService,
private readonly passTroughService: PassTroughService
) {
}

onApplicationBootstrap = async () => {

let selectedVersion = this.versionManager.getSelectedVersion()
let selectedVersion = this.versionManager.getSelectedVersion();

if (!selectedVersion) {
const [{version}] = await this.versionManager.search(['latest']).toPromise()
await this.versionManager.setSelectedVersion(version)
selectedVersion = version
const [{ version }] = await this.versionManager.search(['latest']).toPromise();
await this.versionManager.setSelectedVersion(version);
selectedVersion = version;
}

await this.versionManager.downloadIfNeeded(selectedVersion)
await this.passTroughService.init()
this.program.parse(process.argv)
await this.versionManager.downloadIfNeeded(selectedVersion);
await this.passTroughService.init();
this.program.parse(process.argv);

};

Expand Down

0 comments on commit 4568734

Please sign in to comment.