You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/middlewares.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,10 @@ Nest middleware are, by default, equivalent to [express](https://expressjs.com/e
20
20
21
21
You implement custom Nest middleware in either a function, or in a class with an `@Injectable()` decorator. The class should implement the `NestMiddleware` interface, while the function does not have any special requirements. Let's start by implementing a simple middleware feature using the class method.
22
22
23
+
> warning **Warning**`Express` and `fastify` treat middleware differently and have different syntaxes for middleware.
@@ -44,6 +48,36 @@ export class LoggerMiddleware {
44
48
}
45
49
```
46
50
51
+
#### Use with Fastify
52
+
53
+
The middleware with `fastify` "works", but it retrieves only the raw `req` and `res` objects and not the fastify wrapper. This is a side effect of how `middie` works and `fastify` already talks about it in its documents for more information see [here](https://www.fastify.io/docs/latest/Reference/Middleware/).
54
+
55
+
> warning **Warning** The middleware in `fastify` has an IncomingMessage request type `FastifyRequest['raw']` and a ServerResponse type `FastifyReply['raw']`.
Nest middleware fully supports Dependency Injection. Just as with providers and controllers, they are able to **inject dependencies** that are available within the same module. As usual, this is done through the `constructor`.
0 commit comments