Question presented to candidate:
"Our app has a middleware.ts that redirects logged-out users, rewrites a few legacy URLs and adds a request ID header. Next.js 16 talks about proxy.ts instead. What is it, what exactly do we change, and what could go wrong in the migration?"
What a strong answer should cover:
proxy.tsis the same feature under a new name: a function at the project root (orsrc/) that runs before routing for every matched request and can redirect, rewrite, set headers or respond.- Migration: rename the file and the exported function (
middlewaretoproxy), rename config flags such asskipMiddlewareUrlNormalize; themiddleware-to-proxycodemod does both. - Proxy always runs on the Node.js runtime and a
runtimeexport is an error;middleware.tsis deprecated but still works and still defaults to Edge, so renaming changes the runtime. - Keep it thin and use
config.matcher; do authorization inside each page, Route Handler and Server Action as well, because a matcher change can silently remove coverage. - Having both files is a build error; a
proxy.tsthat still exportsmiddlewareis a build error too.
Clarifying questions expected:
- "Does our middleware depend on the Edge runtime or run on a platform's edge network?" β the guide says to keep
middleware.tsin that case. - "What does it actually do?" β redirects and headers often belong in
next.configinstead.
Code / implementation expected: Yes β a proxy.ts with an auth redirect, a rewrite, a header and a matcher.