Middleware Patterns

Use when designing or reviewing the Next.js request-preprocessing layer — the single root file that runs cross-cutting request/response transforms before route resolution. As of Next.js 16 this file is `proxy.ts` (function `proxy`, Node.js runtime, default export or named); `middleware.ts` (function `middleware`, Edge Runtime by default — Node.js opt-in since 15.5) is deprecated but retained for Edge use cases. Covers: the runtime split (proxy = Node.js, runtime config throws; middleware.ts = Edge by default with its capability ceiling, Node.js opt-in since 15.5), the `matcher` config that decides which paths it runs on, the `NextRequest`/`NextResponse` API for cookies/headers (and `geolocation()`/`ipAddress()` from `@vercel/functions` since `request.geo`/`request.ip` were removed in Next.js 15), the four response shapes (`next`/`rewrite`/`redirect`/direct response), `waitUntil` for background work, the official `next/experimental/testing/server` test utilities, the canonical patterns (auth gate, locale routi

jacob-balslev Updated

File contents

jacob-balslev/skills/tree/main/skills/frontend-engineering/middleware-patterns commit 80b1340f35

Frequently asked questions

npx skillmds@latest add jacob-balslev/middleware-patterns-2