From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Middleware for specific route handlers - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Middleware for specific route handlers
We can also apply the middleware for specific route handlers like GET, POST, PUT, PATCH or DELETE. Let's see how to achieve that. Currently, in the example, all the routes falling under the client route are being watched by the middleware. Let's say we have a post route handler. After all these get handlers, I'll give the post handler and the method name as route four, which returns a message. This is route four under slash client. Now let's say we want the middleware to be applied on all the get handlers and exclude the post handler. So when this kind of situation arises, we define the route inside the for routes method in a different manner. I'll remove the path and we'll give an object instead. In this object, we have to specify two properties. First is the path, which takes the route path. I'll give client slash and the asterisk sign. Also the path property takes the URL path patterns or basically route paths. It supports basic route patterns as well as wildcard patterns using the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction to Nest middlewares3m 46s
-
(Locked)
Implementing middleware3m 45s
-
(Locked)
Registering a middleware5m 20s
-
(Locked)
Route-specific middleware5m 48s
-
(Locked)
Assignment: Checking Content-Type with middleware4m
-
(Locked)
Handling route wildcards3m 19s
-
(Locked)
Middleware for specific route handlers4m 38s
-
(Locked)
Excluding routes3m 49s
-
(Locked)
Controller-driven route middleware2m 15s
-
(Locked)
Understanding functional middleware4m 26s
-
(Locked)
Applying multiple middlewares6m 51s
-
(Locked)
Applying global middlewares3m 52s
-
(Locked)
Assignment: Password encryption middleware10m 19s
-
(Locked)
-
-
-
-
-
-
-
-