Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/pkg #35

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { CharactersModule } from './characters/characters.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';

import { config, environments, validationSchema } from './config';
import { getEnvFilePath, config, validationSchema } from './config';

@Module({
imports: [
ConfigModule.forRoot({
envFilePath: environments[`${process.env.NODE_ENV}`],
envFilePath: getEnvFilePath(),
ignoreEnvFile: process.env.NODE_ENV === 'production' || false,
load: [config],
isGlobal: true,
Expand Down
5 changes: 4 additions & 1 deletion src/config/environments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const environments = {
// List of environments
const environments = {
test: '.env.test',
dev: '.env.dev',
qa: '.env.qa',
stg: '.env.stg',
production: '.env',
};

export const getEnvFilePath = (): string => environments[`${process.env.NODE_ENV}`];
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { NestFactory } from '@nestjs/core';
import { Logger, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ExceptionsFilter } from '@tresdoce-nestjs-toolkit/paas';
import cookieParser from 'cookie-parser';
import compression from 'compression';
import helmet from 'helmet';
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger';
import { ExceptionsFilter } from '@tresdoce-nestjs-toolkit/paas';
import { otelProvider } from '@tresdoce-nestjs-toolkit/tracing';

import { AppModule } from './app.module';
import { otelProvider } from '@tresdoce-nestjs-toolkit/tracing';
import { config } from './config';

async function bootstrap() {
async function bootstrap(): Promise<void> {
otelProvider(config().tracing);
const app = await NestFactory.create(AppModule, {
logger: new Logger(),
});
const appConfig = app.get<ConfigService>(ConfigService)['internalConfig']['config'];
const { server, swagger, project } = appConfig;
const port = parseInt(server.port, 10) || 8080;
const port: number = parseInt(server.port, 10) || 8080;

app.setGlobalPrefix(`${server.context}`);

Expand Down Expand Up @@ -47,7 +47,7 @@ async function bootstrap() {
.setContact(project.author.name, project.author.url, project.author.email)
.addServer(`/${server.context}`)
.build();
const document = SwaggerModule.createDocument(app, config, {
const document: OpenAPIObject = SwaggerModule.createDocument(app, config, {
ignoreGlobalPrefix: true,
});
SwaggerModule.setup(`${server.context}/${swagger.path}`, app, document, {});
Expand All @@ -62,7 +62,7 @@ async function bootstrap() {
});
}

await app.listen(port, async () => {
await app.listen(port, async (): Promise<void> => {
const appServer = `http://localhost:${port}/${server.context}`;
if (swagger.enabled) {
Logger.log(`📚 Swagger is running on: ${appServer}/${swagger.path}`, `${project.name}`);
Expand All @@ -71,4 +71,4 @@ async function bootstrap() {
});
}

(async () => await bootstrap())();
(async (): Promise<void> => await bootstrap())();