Intercepting requests
Starting with Next.js 16, what used to be called Middleware is now called Proxy — the same feature, renamed to reflect that it runs at the network boundary, before a request completes.
Create a proxy.ts file in the project root (or inside src), at the same
level as your app directory. Export the function as either a default export or
a named proxy export. It receives the incoming request and can rewrite,
redirect, modify request or response headers, or respond directly:
// proxy.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function proxy(request: NextRequest) {
return NextResponse.redirect(new URL('/home', request.url));
}
export const config = {
matcher: '/about/:path*',
};
The matcher in the exported config filters which paths run through Proxy, so
it only runs where you need it.
Proxy runs on the Node.js runtime, and it is not meant for slow data
fetching or full authorization. Directives such as use cache and use server
have no effect inside Proxy.
You are about to answer a short quiz on proxy.ts and the matcher.