Files
main.tsmain
What you'll learn
- Write middleware as an @Injectable() class implementing NestMiddleware, with a service injected
- Apply middleware from a module's configure() with MiddlewareConsumer, to a controller's routes only
- Explain why middleware must call next() or end the response, and what it cannot know about the handler
Press Run tests to start the app. Its log appears here.Graded endpoints
A cats route: the middleware records it before the handler runs
Another cats route, another line
forRoutes(CatsController) covers every route of the controller, including ones with parameters
The three cats requests, in order, each as METHOD /path
Reading /stats is not a cats route, so the previous read added no line