Skip to content

Commit

Permalink
fix(app): configure http agent with proxy url if present in environment
Browse files Browse the repository at this point in the history
Fixes ##714
  • Loading branch information
jontze committed Mar 6, 2024
1 parent 6afafd4 commit 9079344
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions apps/generator-cli/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import {Inject, Module, OnApplicationBootstrap} from '@nestjs/common';
import {HttpModule} from '@nestjs/axios';
import {Command} from 'commander';
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 { 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],
controllers: [
VersionManagerController
imports: [
HttpModule.register({
...httpModuleConfig,
}),
],
controllers: [VersionManagerController],
providers: [
UIService,
ConfigService,
Expand All @@ -19,34 +36,33 @@ import {ConfigService, GeneratorService, PassThroughService, UIService, VersionM
VersionManagerService,
{
provide: COMMANDER_PROGRAM,
useValue: new Command('openapi-generator-cli').helpOption(false).usage('<command> [<args>]')
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 passThroughService: PassThroughService
) {
}
) {}

onApplicationBootstrap = async () => {

let selectedVersion = this.versionManager.getSelectedVersion();

if (!selectedVersion) {
const [{version}] = await this.versionManager.search(['latest']).toPromise();
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);

};

}

0 comments on commit 9079344

Please sign in to comment.