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 1
1
import type { MikroOrmMiddlewareModuleOptions , NestMiddlewareConsumer } from './typings' ;
2
- import type { MiddlewareConsumer } from '@nestjs/common' ;
2
+ import { type MiddlewareConsumer , HttpStatus } from '@nestjs/common' ;
3
3
4
4
export 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
+ }
8
18
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' ) ;
11
20
} ;
12
21
13
- return options . forRoutesPath ??
14
- ( isNestMiddleware ( consumer ) && usingFastify ( consumer ) ? '(.*)' : '*' ) ;
22
+ return isFastify ( consumer ) ? '(.*)' : '*' ;
15
23
}
You can’t perform that action at this time.
0 commit comments