The issue involves Cloudflare Proxy integration and runtime environment differences.
The issue reports that `proxy.ts` does not execute when deployed behind Cloudflare Proxy, while `middleware.ts` works fine. The problem seems to be related to the runtime environment or Cloudflare integration. The maintainer has suggested checking the runtime configuration, but the exact cause is still unclear.
https://github.com/shivaluma/report-bug-next16-proxy https://github.com/shivaluma/report-bug-next16-proxy/tree/middleware
npx create-next-app@latest
middleware.ts:// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(req: NextRequest) {
console.log("MIDDLEWARE RUNNING:", req.nextUrl.pathname);
return NextResponse.next();
}
export const config = {
matcher: ["/(.*)"],
};
Deploy the project behind Cloudflare Proxy enabled (Cloudflare orange-cloud ON → proxied traffic).
Visit any route (e.g., /).
You will see the expected log output:
MIDDLEWARE RUNNING: /
Now rename the file from middleware.ts → proxy.ts, and update the function name:
// proxy.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function proxy(req: NextRequest) {
console.log("PROXY RUNNING:", req.nextUrl.pathname);
return NextResponse.next();
}
export const config = {
matcher: ["/(.*)"],
};
Remove the old middleware.ts file.
Ensure only proxy.ts exists in the project root.
Redeploy behind Cloudflare Proxy enabled.
Visit any route again.
proxy.ts file does not execute at all.proxy.ts should execute exactly like middleware.ts, with identical config and behavior, including when Cloudflare Proxy is turned on.
Configuration Usage: output: "standalone"
When using middleware.ts, the middleware executes correctly in:
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!