@@ -450,9 +450,14 @@ describe('Middleware (FastifyAdapter)', () => {
450
450
. apply ( ( req , res , next ) => {
451
451
req . extras = { data : 'Data attached in middleware' } ;
452
452
req . headers [ 'ping' ] = 'pong' ;
453
+
454
+ // When global prefix is set and the route is the root path
455
+ if ( req . originalUrl === '/api' ) {
456
+ return res . end ( JSON . stringify ( { success : true , pong : 'pong' } ) ) ;
457
+ }
453
458
next ( ) ;
454
459
} )
455
- . forRoutes ( '* ' ) ;
460
+ . forRoutes ( '{*path} ' ) ;
456
461
}
457
462
}
458
463
@@ -464,7 +469,7 @@ describe('Middleware (FastifyAdapter)', () => {
464
469
) . createNestApplication < NestFastifyApplication > ( new FastifyAdapter ( ) ) ;
465
470
} ) ;
466
471
467
- it ( `GET forRoutes('* ') with global prefix` , async ( ) => {
472
+ it ( `GET forRoutes('{*path} ') with global prefix (route: /api/pong) ` , async ( ) => {
468
473
app . setGlobalPrefix ( '/api' ) ;
469
474
await app . init ( ) ;
470
475
await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
@@ -483,7 +488,26 @@ describe('Middleware (FastifyAdapter)', () => {
483
488
) ;
484
489
} ) ;
485
490
486
- it ( `GET forRoutes('*') without prefix config` , async ( ) => {
491
+ it ( `GET forRoutes('{*path}') with global prefix (route: /api)` , async ( ) => {
492
+ app . setGlobalPrefix ( '/api' ) ;
493
+ await app . init ( ) ;
494
+ await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
495
+ return app
496
+ . inject ( {
497
+ method : 'GET' ,
498
+ url : '/api' ,
499
+ } )
500
+ . then ( ( { payload } ) =>
501
+ expect ( payload ) . to . be . eql (
502
+ JSON . stringify ( {
503
+ success : true ,
504
+ pong : 'pong' ,
505
+ } ) ,
506
+ ) ,
507
+ ) ;
508
+ } ) ;
509
+
510
+ it ( `GET forRoutes('{*path}') without prefix config` , async ( ) => {
487
511
await app . init ( ) ;
488
512
await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
489
513
return app
@@ -501,7 +525,7 @@ describe('Middleware (FastifyAdapter)', () => {
501
525
) ;
502
526
} ) ;
503
527
504
- it ( `GET forRoutes('* ') with global prefix and exclude patterns` , async ( ) => {
528
+ it ( `GET forRoutes('{*path} ') with global prefix and exclude patterns` , async ( ) => {
505
529
app . setGlobalPrefix ( '/api' , { exclude : [ '/' ] } ) ;
506
530
await app . init ( ) ;
507
531
await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
@@ -511,7 +535,7 @@ describe('Middleware (FastifyAdapter)', () => {
511
535
. expect ( 200 , { success : true , root : true } ) ;
512
536
} ) ;
513
537
514
- it ( `GET forRoutes('* ') with global prefix and global prefix options` , async ( ) => {
538
+ it ( `GET forRoutes('{*path} ') with global prefix and global prefix options` , async ( ) => {
515
539
app . setGlobalPrefix ( '/api' , { exclude : [ '/' ] } ) ;
516
540
await app . init ( ) ;
517
541
await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
@@ -528,7 +552,7 @@ describe('Middleware (FastifyAdapter)', () => {
528
552
. expect ( 200 , { success : true , root : true } ) ;
529
553
} ) ;
530
554
531
- it ( `GET forRoutes('* ') with global prefix that not starts with /` , async ( ) => {
555
+ it ( `GET forRoutes('{*path} ') with global prefix that not starts with /` , async ( ) => {
532
556
app . setGlobalPrefix ( 'api' ) ;
533
557
await app . init ( ) ;
534
558
await app . getHttpAdapter ( ) . getInstance ( ) . ready ( ) ;
0 commit comments