Middleware migration
What you need to know
Migrating middleware to Proxy in Next.js 16 is a convention and runtime change. Review the old behavior and dependencies before renaming the file and function.
By the end, you can: compare runtime and convention changes; retest authorization boundaries.
Compare the convention without installing a codemod
Before (legacy): middleware.ts, export function middleware(request)After (16.x): proxy.ts, export function proxy(request)Review: runtime configuration, dependency support, matcher, skipProxyUrlNormalizeExpected behavior: This is a migration worksheet, not executable source or a guarantee of Edge deployment support.
How it works
Older middleware examples often assume an Edge runtime; support evolved across releases. In the proposed 16.x Proxy lane the runtime is Node.js and the file does not accept a runtime export/config setting. Do not copy runtime: edge or runtime: nodejs into the new file. If an Edge-only deployment is required, review the supported migration options for the exact release and host rather than assuming equivalent behavior. The official upgrade guide documents a middleware-to-proxy codemod; it is a code transformation, not a proof of compatibility. Inspect a reviewed tool version and run it only on a disposable branch with approved dependencies. Compare matcher rules, headers, cookies, redirect status, URL normalization and any older skipMiddlewareUrlNormalize configuration (modern name skipProxyUrlNormalize). Keep session screening inexpensive; actual authentication and object access belong in the DAL, Route Handler or Server Function. Test a direct request to every protected endpoint regardless of the Proxy match. Server Functions are invoked as POST requests to the route where they are used, so excluding that path from the matcher can also exclude the action invocation from Proxy. The action must verify permissions independently.
Perform only early navigation screening
import { NextResponse, type NextRequest } from 'next/server';export function proxy(request: NextRequest) { if (request.method === 'GET' && !request.cookies.has('session')) { return NextResponse.redirect(new URL('/sign-in', request.url)); } return NextResponse.next();}export const config = { matcher: ['/account/:path*'] };Expected behavior: A missing cookie redirects GET account visits. Presence merely allows the request to reach the real authentication and authorization checks; it does not prove a valid session.
Common mistake
Never replace a server-side permission check with a cookie-presence check. Do not trust a renamed file, successful codemod or a successful build as evidence of preserved access restrictions.
Practice and verification
Write a migration checklist with exact old/new versions, runtime requirements, three allowed and denied access tests, a normal asset request and rollback. The fixture uses no real session credentials.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.