Still True?
← Back to the board
Middleware

Put request middleware in middleware.ts at the project root. Scope it with a config.matcher export and it runs on the Edge runtime.

officialNext.js docs (Pages Router and v13 to v14 era)confidence 55%current as of Jun 2024

The established pattern is a middleware.ts file at the project or src root that exports a middleware function. You limit which paths it runs on with an exported config.matcher. It runs on the Edge runtime by default. Next.js 16 deprecated this in favor of proxy.ts on the Node.js runtime.

Related claims