import { getEnv , isProd } from '@koh/common' ; import { INestApplication , ValidationPipe } from '@nestjs/common' ; import { NestFactory } from '@nestjs/core' ; import { RewriteFrames } from '@sentry/integrations' ; import * as Sentry from '@sentry/node' ; import * as Tracing from '@sentry/tracing' ; import * as cookieParser from 'cookie-parser' ; import * as morgan from 'morgan' ; import { AppModule } from './app.module' ; import { StripUndefinedPipe } from './stripUndefined.pipe' ; export async function bootstrap ( hot ) { const app = await NestFactory . create ( AppModule , { logger : [ 'error' , 'warn' , 'log' , 'debug' , 'verbose' ] , } ) ; if ( process . env . NODE_ENV === 'production' ) { setupAPM ( app ) ; } app . enableShutdownHooks ( ) ; addGlobalsToApp ( app ) ; app . setGlobalPrefix ( 'api/v1' ) ; if ( isProd ( ) ) { console . log ( `Running production at ${ process . env . DOMAIN }.` ) ; } else { console . log ( `Running non-production at ${ process . env . DOMAIN }. THIS MSG SHOULD NOT APPEAR ON PROD VM` ) ; } addGlobalsToApp ( app ) ; app . setGlobalPrefix ( 'api/v1' ) ; app . use ( morgan ( 'dev' ) ) ; await app . listen ( 3002 ) ; if ( hot ) { hot . accept ( ) ; hot . dispose ( ( ) => app . close ( ) ) ; } } function setupAPM ( app ) { Sentry . init ( { dsn : process . env . SENTRY_APM_DSN , tracesSampleRate : 0.2 , integrations : [ new Sentry . Integrations . Http ( { tracing : true } ) , new Tracing . Integrations . Postgres ( ) , new Tracing . Integrations . Express ( { app : app . getHttpAdapter ( ) . getInstance ( ) , } ) , new RewriteFrames ( ) , ] , release : process . env . SERVICE_VERSION , environment : getEnv ( ) , } ) ; app . use ( Sentry . Handlers . requestHandler ( ) ) ; app . use ( Sentry . Handlers . tracingHandler ( ) ) ; } export function addGlobalsToApp ( app ) { app . useGlobalPipes ( new ValidationPipe ( { whitelist : true , forbidNonWhitelisted : true , transform : true , } ) ) ; app . useGlobalPipes ( new StripUndefinedPipe ( ) ) ; app . use ( cookieParser ( ) ) ; }