import { join } from 'path' ; import * as CookieParser from 'cookie-parser' ; import { renderFile } from 'ejs' ; import { urlencoded } from 'express' ; import * as helmet from 'helmet' ; import { NestFactory } from '@nestjs/core' ; import { NestExpressApplication } from '@nestjs/platform-express' ; import { ConfigService } from '@fc/config' ; import { LoggerService } from '@fc/logger' ; import { AppConfig , MockServiceProviderConfig , } from '@fc/mock-service-provider' ; import { SessionConfig } from '@fc/session' ; import { AppModule } from './app.module' ; import config from './config' ; async function bootstrap ( ) { const configService = new ConfigService ( { config , schema : MockServiceProviderConfig , } ) ; const { viewsPaths , assetsPaths , httpsOptions : { key , cert } , } = configService . get < AppConfig > ( 'App' ) ; const appModule = AppModule . forRoot ( configService ) ; const httpsOptions = key && cert ? { cert , key } : null ; const app = await NestFactory . create < NestExpressApplication > ( appModule , { see https see https see https bodyParser : false , httpsOptions , } ) ; see https see https app . set ( 'query parser' , 'simple' ) ; see https app . use ( helmet ( ) ) ; app . use ( helmet . contentSecurityPolicy ( { directives : { defaultSrc : [ "'self'" ] , TODO see https scriptSrc : [ "'self'" , "'unsafe-inline'" , 'stackpath.bootstrapcdn.com' ] , styleSrc : [ "'self'" , "'unsafe-inline'" , 'stackpath.bootstrapcdn.com' ] , } , } ) ) ; app . use ( helmet . permittedCrossDomainPolicies ( ) ) ; see body-parser . md app . use ( urlencoded ( { extended : false } ) ) ; const logger = await app . resolve ( LoggerService ) ; app . useLogger ( logger ) ; app . engine ( 'ejs' , renderFile ) ; app . set ( 'views' , viewsPaths . map ( ( path ) => join ( __dirname , path , 'views' ) ) ) ; app . setViewEngine ( 'ejs' ) ; assetsPaths . forEach ( ( path ) => { app . useStaticAssets ( join ( __dirname , path , 'public' ) ) ; } ) ; const { cookieSecrets } = configService . get < SessionConfig > ( 'Session' ) ; app . use ( CookieParser ( cookieSecrets ) ) ; await app . listen ( 3000 ) ; } bootstrap ( ) ;