seanpmaxwell/overnight

Class Middleware apply to all routes in all controllers with the same route prefix rather than all routes in that particular class

Closed this issue · 2 comments

First of all, awesome works! Great module. Thank you.

I found this little issue in relating to middleware. Not sure wether it is by design or not. Could you help check.


Versions: ^1.6.9

Code Example:

1.Controller A - with route prefix /api/v1 attach to middlewareA



@Controller('api/v1/')
@ClassMiddleware([middleWareA])
export class ClassA {
    @Post('routeA1')
    private async a1(request: Request, response: Response) {
        return response.status(OK).json({})
    }

    @Post('routeA2')
    private async a2(request: Request, response: Response) {
        return response.status(OK).json({})
    }
}
  1. Controller B using the same prefix /api/v1 but has not assigned any middleware.
@Controller('api/v1/')
export class ClassB {
    @Post('routeB1')
    private async b1(request: Request, response: Response) {
        return response.status(OK).json({})
    }
}

Expected result:

middlewareA get invoke only in route in controller A

  • /api/v1/routeA1
  • /api/v1/routeA2

controller B /api/v1/routeB1 should get invoke directly without middlewareA

Actual result:

All route with prefix /api/v1/ got invoke with middlewareA

Hmm I haven't encountered this scenario in Express but... if that's the expected behavior for express (which I'm guessing it is since overnight just uses Router() objects under the hood) then that's the way it should be.

Can I close this issue?