@@ -9,30 +9,29 @@ import {Logger} from "@nestjs/common";
99import * as process from "process" ;
1010import * as dotenv from "dotenv" ;
1111import { FastifyListenOptions } from "fastify/types/instance" ;
12+ import { RawServerDefault } from "fastify" ;
1213
1314dotenv . config ( ) ;
1415
1516const logger : Logger = new Logger ( "App" ) ;
1617
1718async function bootstrap ( ) {
18- const app = await NestFactory . create < NestFastifyApplication > (
19+ const app : NestFastifyApplication < RawServerDefault > = await NestFactory . create < NestFastifyApplication > (
1920 AppModule ,
2021 new FastifyAdapter ( { exposeHeadRoutes : true } ) ,
2122 ) ;
2223 await loadServer ( app ) ;
23- const port = process . env . PORT || 4000 ;
2424 // @ts -ignore
2525 await app . listen ( {
26- port : port ,
26+ port : process . env . PORT || 4000 ,
2727 host : "0.0.0.0" ,
2828 } as FastifyListenOptions ) ;
2929 app . enableShutdownHooks ( ) ;
30- logger . log ( `Listening on http://0.0.0.0:${ port } ` ) ;
3130}
3231
3332async function loadServer ( server : NestFastifyApplication ) {
3433 // Config
35- server . setGlobalPrefix ( process . env . PREFIX ) ;
34+ server . setGlobalPrefix ( process . env . PREFIX || "" ) ;
3635 server . enableCors ( {
3736 origin : "*" ,
3837 } ) ;
@@ -56,7 +55,7 @@ async function loadServer(server: NestFastifyApplication){
5655 const document = SwaggerModule . createDocument ( server , config ) ;
5756 const theme = new SwaggerTheme ( ) ;
5857 const customCss = theme . getBuffer ( SwaggerThemeNameEnum . DARK ) ;
59- SwaggerModule . setup ( "" , server , document , {
58+ SwaggerModule . setup ( process . env . PREFIX || "" , server , document , {
6059 swaggerOptions : {
6160 filter : true ,
6261 displayRequestDuration : true ,
@@ -69,4 +68,6 @@ async function loadServer(server: NestFastifyApplication){
6968 } ) ;
7069}
7170
72- bootstrap ( ) ;
71+ bootstrap ( ) . then ( ( ) => {
72+ logger . log ( `Listening on http://0.0.0.0:${ process . env . PORT || 4000 } ` ) ;
73+ } ) ;
0 commit comments