middleware.js

API reference for the middleware.js file (deprecated, renamed to proxy.js).

The middleware.js file convention has been deprecated in Next.js 16 and renamed to proxy.js.

All functionality remains the same — only the file and export names have changed. See the Migration to Proxy section for details on how to migrate.

You can automatically migrate by running:

npx @next/codemod@canary middleware-to-proxy .

For full documentation, see the proxy.js API reference.