Loading...
Loading...
Next.js 16 proxy convention (replacing middleware). Use when creating middleware, handling URL rewrites, or when the user mentions proxy.ts, middleware.ts, or route interception in Next.js 16+.
npx skill4agent add blink-new/claude nextjs-16-proxymiddlewareproxy| Old (Next.js 15) | New (Next.js 16+) |
|---|---|
| |
| |
| Same location | Same location |
proxy.tsapppagessrc/
├── proxy.ts ← Correct location
├── app/
│ └── ...app/src/
├── app/
│ ├── proxy.ts ← Wrong location
│ └── ...import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
// Example: rewrite /uploads/* to /api/uploads/*
if (pathname.startsWith("/uploads/")) {
const newUrl = request.nextUrl.clone();
newUrl.pathname = pathname.replace("/uploads/", "/api/uploads/");
return NextResponse.rewrite(newUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/uploads/:path*"],
};[teamSlug]next.config.ts/uploads/image.png[teamSlug]teamSlug = "uploads"proxy.tsnext.config.tsnpx @next/codemod@canary middleware-to-proxy .middleware.tsproxy.tsmiddlewareproxy