env.inspector
04 / 10Handle with careEdge runtimeresponse headers5KB per-variable limit

Middleware & the Edge runtime

Code that runs before your app still runs somewhere, and what it attaches to a request or response is just as public as a page body — headers included.

ℹNaming update in Next.js 16
This project is pinned to Next.js 16.2.10, where middleware.js has been renamed to proxy.js (and the exported middleware function to proxy) to make the network boundary explicit. proxy.jsalways runs on the Node.js runtime and that can't be configured away. The old middleware.js file still works for Edge-runtime use cases, but is deprecated — if you're following an older tutorial that uses middleware.ts and runtime: 'edge', that's why it looks different from what ships here.

Live demo: response headers set in proxy.js

Every request to /api/middleware-demo passes through proxy.jsfirst, which attaches a few response headers before the Route Handler's own response continues on.

GET /api/middleware-demo
// response headers will appear here
proxy.js
export function proxy(request) {
  if (request.nextUrl.pathname === '/api/middleware-demo') {
    const response = NextResponse.next()

    // SAFE — non-sensitive
    response.headers.set('x-demo-site-name', process.env.NEXT_PUBLIC_SITE_NAME)

    // DANGER — a response header is exactly as public as a response body
    response.headers.set('x-demo-danger-leak', process.env.STRIPE_SECRET_KEY)

    return response
  }
  return NextResponse.next()
}
⚠The Edge runtime, if you do reach for it
Route Handlers and (legacy) Edge middleware can still opt into runtime: 'edge'. Vercel caps environment variables at 64KB total per deployment, but Edge Functions and Edge middleware are limited to 5KB per individual variable — large JWTs, certificates, or bundled service-account JSON can quietly hit that ceiling in a way they never would in the Node.js runtime.
Verify it yourself
  1. 1
    Click "Fetch & inspect headers" above, then open DevTools → Network → select the middleware-demo request → Headers. You'll see all three custom headers listed as plain response headers.
  2. 2
    From a terminal once deployed: curl -I https://env-inspector-zeta.vercel.app/api/middleware-demo shows the same headers with zero JavaScript involved — headers are metadata on the HTTP response, not something a browser adds.
  3. 3
    Notice what isn't here: request headers your own proxy reads (like authorization) are never sent back to the client unless code explicitly copies them onto the response, same rule as everything else in this project.
Self-check0/3 answered
  • proxy.js (Next.js 16’s renamed middleware.js) always runs on the Node.js runtime.

  • A value set with response.headers.set() in proxy.js is only visible to your own server code.

  • The Edge runtime’s 5KB-per-variable limit applies to every environment variable in a Vercel project.