Skip to content

Commit

Permalink
Simplify middleware examples (#8176)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>
  • Loading branch information
3 people committed May 4, 2024
1 parent ab5bcdb commit 9052ff7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/content/docs/en/guides/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Middleware also allows you to set and share request-specific information across
2. Inside this file, export an [`onRequest()`](/en/reference/api-reference/#onrequest) function that can be passed a [`context` object](#the-context-object) and `next()` function. This must not be a default export.

```js title="src/middleware.js"
export function onRequest ({ locals, request }, next) {
export function onRequest (context, next) {
// intercept data from a request
// optionally, modify the properties in `locals`
locals.title = "New title";
context.locals.title = "New title";

// return a Response or the result of calling `next()`
return next();
Expand Down Expand Up @@ -58,11 +58,11 @@ This `locals` object is forwarded across the request handling process and is ava
You can store any type of data inside `locals`: strings, numbers, and even complex data types such as functions and maps.

```js title="src/middleware.js"
export function onRequest ({ locals, request }, next) {
export function onRequest (context, next) {
// intercept data from a request
// optionally, modify the properties in `locals`
locals.user.name = "John Wick";
locals.welcomeTitle = () => {
context.locals.user.name = "John Wick";
context.locals.welcomeTitle = () => {
return "Welcome back " + locals.user.name;
};

Expand Down

0 comments on commit 9052ff7

Please sign in to comment.