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
  • Loading branch information
jontze committed Apr 15, 2024
1 parent 8b56098 commit a4ef67e
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 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,37 @@ import {ConfigService, GeneratorService, PassThroughService, UIService, VersionM
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')
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}
]
{ 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
) {
}
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 a4ef67e

Please sign in to comment.