Skip to content

Commit db1de21

Browse files
icyJosephijjk
andauthored
docs: Middleware explicit runtime differences (#83348)
In previous docs versions, while not explicitly stated, it was rather clearer that middleware has its own runtime. Also, people who have used bundle-analyzer would for example be familiar with the 3 bundles, or those who have worked with `next.config.js`/instrumentation would understand that there's some different runtimes at play going on there, but those who exclusively work with middleware might still miss on this detail. --------- Co-authored-by: JJ Kasper <[email protected]>
1 parent e97fc23 commit db1de21

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/01-app/03-api-reference/03-file-conventions/middleware.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ The `middleware.js|ts` file is used to write [Middleware](/docs/app/api-referenc
1212

1313
Middleware executes before routes are rendered. It's particularly useful for implementing custom server-side logic like authentication, logging, or handling redirects.
1414

15+
> **Good to know**:
16+
>
17+
> Middleware is meant to be invoked separately of your render code and in optimized cases deployed to your CDN for fast redirect/rewrite handling, you should not attempt relying on shared modules or globals.
18+
>
19+
> To pass information from Middleware to your application, use [headers](#setting-headers), [cookies](#using-cookies), [rewrites](/docs/app/api-reference/functions/next-response#rewrite), [redirects](/docs/app/api-reference/functions/next-response#redirect), or the URL.
20+
1521
Create a `middleware.ts` (or `.js`) file in the project root, or inside `src` if applicable, so that it is located at the same level as `pages` or `app`.
1622

1723
```tsx filename="middleware.ts" switcher
@@ -281,7 +287,7 @@ export function middleware(request) {
281287
}
282288
```
283289

284-
## Using Cookies
290+
### Using Cookies
285291

286292
Cookies are regular headers. On a `Request`, they are stored in the `Cookie` header. On a `Response` they are in the `Set-Cookie` header. Next.js provides a convenient way to access and manipulate these cookies through the `cookies` extension on `NextRequest` and `NextResponse`.
287293

0 commit comments

Comments
 (0)