File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed
Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change 11import type { MikroOrmMiddlewareModuleOptions , NestMiddlewareConsumer } from './typings' ;
2- import type { MiddlewareConsumer } from '@nestjs/common' ;
2+ import { type MiddlewareConsumer , HttpStatus } from '@nestjs/common' ;
33
44export function forRoutesPath ( options : MikroOrmMiddlewareModuleOptions , consumer : MiddlewareConsumer ) {
5- const isNestMiddleware = ( consumer : MiddlewareConsumer ) : consumer is NestMiddlewareConsumer => {
6- return typeof ( consumer as any ) . httpAdapter === 'object' ;
7- } ;
5+ if ( options . forRoutesPath ) {
6+ return options . forRoutesPath ;
7+ }
8+
9+ // detect nest v11 based on a newly added enum value
10+ if ( HttpStatus . MULTI_STATUS ) {
11+ return '{*all}' ;
12+ }
13+
14+ const isFastify = ( consumer : MiddlewareConsumer ) => {
15+ if ( typeof ( consumer as any ) . httpAdapter !== 'object' ) {
16+ return false ;
17+ }
818
9- const usingFastify = ( consumer : NestMiddlewareConsumer ) => {
10- return consumer . httpAdapter . constructor . name . toLowerCase ( ) . startsWith ( 'fastify' ) ;
19+ return ( consumer as NestMiddlewareConsumer ) . httpAdapter . constructor . name . toLowerCase ( ) . startsWith ( 'fastify' ) ;
1120 } ;
1221
13- return options . forRoutesPath ??
14- ( isNestMiddleware ( consumer ) && usingFastify ( consumer ) ? '(.*)' : '*' ) ;
22+ return isFastify ( consumer ) ? '(.*)' : '*' ;
1523}
You can’t perform that action at this time.
0 commit comments