Skip to content

Commit a4644d3

Browse files
committed
Move middleware doc to reference links
1 parent b0587f1 commit a4644d3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

docs/how-to/middleware.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unstable: true
1212

1313
<docs-warning>The middleware feature is currently experimental and subject to breaking changes. Use the `future.unstable_middleware` flag to enable it.</docs-warning>
1414

15-
Middleware allows you to run code before and after the `Response` generation for the matched path. This enables common patterns like authentication, logging, error handling, and data preprocessing in a reusable way.
15+
Middleware allows you to run code before and after the `Response` generation for the matched path. This enables [common patterns][common-patterns] like authentication, logging, error handling, and data preprocessing in a reusable way.
1616

1717
Middleware runs in a nested chain, executing from parent routes to child routes on the way "down" to your route handlers, then from child routes back to parent routes on the way "up" after a `Response` is generated.
1818

@@ -352,7 +352,7 @@ const user = context.get(userContext); // Returns User type
352352

353353
#### Context and AsyncLocalStorage
354354

355-
Node provides an [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) API which gives you a way to provide values through asynchronous execution contexts. While this is a Node API, most modern runtimes have have made it (mostly) available (i.e., [Cloudflare](https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/), [Bun](https://bun.sh/blog/bun-v0.7.0#asynclocalstorage-support), [Deno](https://docs.deno.com/api/node/async_hooks/~/AsyncLocalStorage)).
355+
Node provides an [`AsyncLocalStorage`][asynclocalstorage] API which gives you a way to provide values through asynchronous execution contexts. While this is a Node API, most modern runtimes have have made it (mostly) available (i.e., [Cloudflare][cloudflare], [Bun][bun], [Deno][deno]).
356356

357357
In theory, we could have leveraged `AsyncLocalStorage` directly as the way to pass values from middlewares to to child routes, but the lack of 100% cross-platform compatibility was concerning enough that we wanted to still ship a first-class `context` API so there would be way to publish reusable middleware packages guaranteed to work in a runtime-agnostic manner.
358358

@@ -687,5 +687,10 @@ export async function loader({
687687
}
688688
```
689689

690+
[common-patterns]: #common-patterns
690691
[server-client]: #server-vs-client-middleware
691692
[getloadcontext]: #changes-to-getloadcontextapploadcontext
693+
[asynclocalstorage]: https://nodejs.org/api/async_context.html#class-asynclocalstorage
694+
[cloudflare]: https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/
695+
[bun]: https://bun.sh/blog/bun-v0.7.0#asynclocalstorage-support
696+
[deno]: https://docs.deno.com/api/node/async_hooks/~/AsyncLocalStorage

0 commit comments

Comments
 (0)