Skip to content
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
7 changes: 5 additions & 2 deletions src/content/docs/en/guides/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Middleware also allows you to set and share request-specific information across
// intercept data from a request
// optionally, modify the properties in `locals`
context.locals.title = "New title";
context.locals.property = "information";

// return a Response or the result of calling `next()`
return next();
Expand Down Expand Up @@ -62,10 +63,12 @@ You can store any type of data inside `locals`: strings, numbers, and even compl
export function onRequest (context, next) {
// intercept data from a request
// optionally, modify the properties in `locals`
context.locals.user.name = "John Wick";
context.locals.user = { id: 1, name: "John Wick" };
context.locals.welcomeTitle = () => {
return "Welcome back " + locals.user.name;
return "Welcome back " + context.locals.user.name;
Comment thread
ArmandPhilippot marked this conversation as resolved.
};
context.locals.orders = new Map([["1", { product: "socks" }]]);
context.locals.property = "information";

// return a Response or the result of calling `next()`
return next();
Expand Down
Loading