Skip to content

Commit 0cc94d5

Browse files
author
Sergei Shevlyagin
committed
responding to feedback
1 parent c0e414b commit 0cc94d5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

content/middlewares.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,18 @@ app.use(logger);
243243
await app.listen(3000);
244244
```
245245

246+
> info **Hint** Accessing the DI container in a global middleware is not possible. You can use a [functional middleware](middleware#functional-middleware) instead when using `app.use()`. Alternatively, you can use a class middleware and consume it with `.forRoutes('*')` within the `AppModule` (or any other module).
247+
246248
#### Default body parser middleware
247249

248-
When using the `express` adapter, the NestJS app will register `json` and `urlencoded` from the package `body-parser` by default. This can be turned off by setting the `bodyParser` flag to `false` when creating the application.
250+
When using the `express` adapter, the NestJS app will register `json` and `urlencoded` from the package `body-parser` by default.
251+
- `urlencoded` is used with the `{extended: true}` flag and the optional `rawBody` flag if set in your `NestApplicationOptions`.
252+
- `body-parser` is used with the optional `rawBody` flag if set in your `NestApplicationOptions`.
253+
254+
This can be turned off by setting the `bodyParser` flag to `false` when creating the application.
249255

250256
```typescript
251257
const app = await NestFactory.create(AppModule, {bodyParser: false});
252258
```
253259

254260
Without doing that, you won't be able to apply custom bodyParser middleware to individual routes.
255-
256-
257-
> info **Hint** Accessing the DI container in a global middleware is not possible. You can use a [functional middleware](middleware#functional-middleware) instead when using `app.use()`. Alternatively, you can use a class middleware and consume it with `.forRoutes('*')` within the `AppModule` (or any other module).

0 commit comments

Comments
 (0)