Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify middleware examples #8176

Merged
merged 3 commits into from
May 4, 2024
Merged
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
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
Loading