Skip to content

Commit 98eb907

Browse files
author
Sergei Shevlyagin
committed
responding to feedback
1 parent 0bebee2 commit 98eb907

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

content/middlewares.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export class AppModule {
122122

123123
> info **Hint** The `configure()` method can be made asynchronous using `async/await` (e.g., you can `await` completion of an asynchronous operation inside the `configure()` method body).
124124
125+
> warning **Warning** When using the `express` adapter, the NestJS app will register `json` and `urlencoded` from the package `body-parser` by default. This means if you want to customize that middleware per route, you need to turn off the global middleware by setting the `bodyParser` flag to `false` when creating the application with `NestFactory.create()`.
126+
125127
#### Route wildcards
126128

127129
Pattern based routes are supported as well. For instance, the asterisk is used as a **wildcard**, and will match any combination of characters:
@@ -244,17 +246,3 @@ await app.listen(3000);
244246
```
245247

246248
> 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-
248-
#### Default body parser middleware
249-
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.
255-
256-
```typescript
257-
const app = await NestFactory.create(AppModule, {bodyParser: false});
258-
```
259-
260-
Without doing that, you won't be able to apply custom bodyParser middleware to individual routes.

0 commit comments

Comments
 (0)