File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const mapToClass = <T extends Function | Type<any>>(
2929 excludedRoutes : RouteInfoRegex [ ] ,
3030 httpAdapter : HttpServer ,
3131) => {
32- if ( isClass ( middleware ) ) {
32+ if ( isMiddlewareClass ( middleware ) ) {
3333 if ( excludedRoutes . length <= 0 ) {
3434 return middleware ;
3535 }
@@ -59,8 +59,17 @@ export const mapToClass = <T extends Function | Type<any>>(
5959 ) ;
6060} ;
6161
62- export function isClass ( middleware : any ) : middleware is Type < any > {
63- return middleware . toString ( ) . substring ( 0 , 5 ) === 'class' ;
62+ export function isMiddlewareClass ( middleware : any ) : middleware is Type < any > {
63+ const middlewareStr = middleware . toString ( ) ;
64+ if ( middlewareStr . substring ( 0 , 5 ) === 'class' ) {
65+ return true ;
66+ }
67+ const middlewareArr = middlewareStr . split ( ' ' ) ;
68+ return (
69+ middlewareArr [ 0 ] === 'function' &&
70+ / [ A - Z ] / . test ( middlewareArr [ 1 ] ?. [ 0 ] ) &&
71+ typeof middleware . prototype ?. use === 'function'
72+ ) ;
6473}
6574
6675export function assignToken ( metatype : Type < any > , token = uuid ( ) ) : Type < any > {
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import * as sinon from 'sinon';
55import {
66 assignToken ,
77 filterMiddleware ,
8- isClass ,
8+ isMiddlewareClass ,
99 isRouteExcluded ,
1010 mapToClass ,
1111} from '../../middleware/utils' ;
@@ -63,15 +63,15 @@ describe('middleware utils', () => {
6363 } ) ;
6464 } ) ;
6565 } ) ;
66- describe ( 'isClass ' , ( ) => {
66+ describe ( 'isMiddlewareClass ' , ( ) => {
6767 describe ( 'when middleware is a class' , ( ) => {
6868 it ( 'should returns true' , ( ) => {
69- expect ( isClass ( Test ) ) . to . be . true ;
69+ expect ( isMiddlewareClass ( Test ) ) . to . be . true ;
7070 } ) ;
7171 } ) ;
7272 describe ( 'when middleware is a function' , ( ) => {
7373 it ( 'should returns false' , ( ) => {
74- expect ( isClass ( fnMiddleware ) ) . to . be . false ;
74+ expect ( isMiddlewareClass ( fnMiddleware ) ) . to . be . false ;
7575 } ) ;
7676 } ) ;
7777 } ) ;
You can’t perform that action at this time.
0 commit comments