All files / src/shared bootstrap.ts

0% Statements 0/36
0% Branches 0/1
0% Functions 0/3
0% Lines 0/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                                                                           
import { HttpStatus, INestApplication, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { json, urlencoded } from 'express';
import * as httpContext from 'express-http-context';
import helmet from 'helmet';
import * as responseTime from 'response-time';
import { CustomExceptionFilter } from 'src/exception/exception.filter';
import { LoggingInterceptor } from 'src/interceptors/logging.interceptor';
import { AppModule } from 'src/modules/app.module';
import { EventSdkGuard } from 'src/packages/event-sdk';
import { getKafkaConfig } from './config/kafka.config';
import { getRabbitMQConfig } from './config/rabbitmq.config';
import ENV from './env';
import { configureSwagger } from './swagger';
 
export function configureMiddlewares(app: INestApplication) {
  app.use(helmet());
  app.use(urlencoded({ extended: true }));
  app.use(json());
  app.use(httpContext.middleware);
  app.use(responseTime({ header: 'x-response-time' }));
  app.useGlobalInterceptors(new LoggingInterceptor());
  app.useGlobalFilters(new CustomExceptionFilter());
  app.useGlobalGuards(new EventSdkGuard());
  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
      errorHttpStatusCode: HttpStatus.BAD_REQUEST,
      validationError: {
        target: true,
        value: true,
      },
    }),
  );
}
 
export async function configureMicroservices(app: INestApplication) {
  app.connectMicroservice(getRabbitMQConfig(), { inheritAppConfig: true });
  Iif (!ENV.KAFKA.IS_CUSTOM_CLIENT)
    app.connectMicroservice(getKafkaConfig(), { inheritAppConfig: true });
  await app.startAllMicroservices();
}
 
export async function bootstrap() {
  const app = await NestFactory.create(AppModule);
 
  configureMiddlewares(app);
  app.setGlobalPrefix(ENV.SERVICE.BASE_URL);
  configureSwagger(app);
  await configureMicroservices(app);
 
  await app.listen(ENV.SERVICE.PORT);
}