Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion node.js/cds-serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ srv/cat-service.js #> service implementation used by default
For each service served at a certain protocol, the framework registers a configurable set of express middlewares by default like so:

```js
app.use (cds.middlewares.before, protocol_adapter)
app.use (cds.middlewares.before, protocol_adapter, cds.middlewares.after)
```

The standard set of middlewares uses the following order:
Expand All @@ -222,6 +222,16 @@ cds.middlewares.before = [
]
```

```js
cds.middlewares.after = [
cds_error_handler(), // provides final error handling
]
```

::: tip Custom error middleware before `cds_error_handler`
To invoke a custom error middleware successfully, you must register it _before_ the built-in `cds_error_handler`. You can achieve that, for example, by adding the middleware using `cds.middlewares.after.unshift()`.
:::

::: warning _Be aware of the interdependencies of middlewares_ <!-- -->
_ctx_model_ requires that _cds.context_ middleware has run before.
_ctx_auth_ requires that _authentication_ has run before.
Expand Down