Skip to content

Commit

Permalink
docs(routing): Note on middleware returns
Browse files Browse the repository at this point in the history
Better describe middleware and how returning within it behaves
  • Loading branch information
oof2win2 authored Nov 4, 2023
1 parent b3dbcb2 commit 9ebb232
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/content/1.guide/3.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ nitro.config.ts
### Simple Middleware

Middleware are defined exactly like route handlers with the only exception that they should not return anything.
Returning from middleware behaves like returning from a request - the value will be returned as a response and further code will not be ran.

```ts [middleware/auth.ts]
export default defineEventHandler((event) => {
Expand All @@ -181,7 +182,7 @@ export default defineEventHandler((event) => {
```

::alert
Returning anything from a middleware will close the request and should be avoided!
Returning anything from a middleware will close the request and should be avoided! Any returned value from middleware will be the response and further code will not be executed.
::

### Execution Order
Expand Down

0 comments on commit 9ebb232

Please sign in to comment.