Skip to content

Commit

Permalink
Set application port from environment (safe-global#223)
Browse files Browse the repository at this point in the history
- Sets the application port from the local environment (value set by `APPLICATION_PORT`)
- If `APPLICATION_PORT` is not set, the default port `3000` will be used (default)
  • Loading branch information
fmrsabino authored Jan 16, 2023
1 parent 25f220a commit 494635e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/entities/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default () => ({
version: process.env.npm_package_version || '',
buildNumber: process.env.GITHUB_RUN_NUMBER || '',
},
applicationPort: process.env.APPLICATION_PORT || '3000',
exchange: {
baseUri:
process.env.EXCHANGE_API_BASE_URI || 'http://api.exchangeratesapi.io/v1',
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { DataSourceErrorFilter } from './routes/common/filters/data-source-error.filter';
import { IConfigurationService } from './config/configuration.service.interface';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand All @@ -23,7 +24,12 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('', app, document);

await app.listen(3000);
const configurationService: IConfigurationService =
app.get<IConfigurationService>(IConfigurationService);
const applicationPort: string =
configurationService.getOrThrow('applicationPort');

await app.listen(applicationPort);
}

bootstrap();

0 comments on commit 494635e

Please sign in to comment.