nextjs - 💡(How to fix) Fix Proxy not work in production mode [5 comments, 6 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85711Fetched 2026-04-08 02:14:15
View on GitHub
Comments
5
Participants
6
Timeline
15
Reactions
0
Timeline (top)
commented ×5labeled ×2mentioned ×2subscribed ×2

Code Example

import { NextRequest, NextResponse } from "next/server";

export const locales = ["en", "nl"] as const;
export type Lang = (typeof locales)[number];

// Get the preferred locale, similar to the above or using a library
function getLocale(request: NextRequest) {
	console.log("Call proxy");
	const acceptLanguage = request.headers.get("accept-language");
	if (!acceptLanguage) return locales[0];

	const languages = acceptLanguage.split(",").map((lang) => lang.trim());
	const matchedLocale = languages.find((lang) =>
		locales.includes(lang as never)
	);
	return matchedLocale || locales[0];
}

export function proxy(request: NextRequest) {
	// Check if there is any supported locale in the pathname
	const { pathname } = request.nextUrl;
	const pathnameHasLocale = locales.some(
		(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
	);

	if (pathnameHasLocale) return;

	// Redirect if there is no locale
	const locale = getLocale(request);
	request.nextUrl.pathname = `/${locale}${pathname}`;
	// e.g. incoming request is /products
	// The new URL is now /en-US/products
	return NextResponse.redirect(request.nextUrl);
}

export const config = {
	matcher: [
		// Skip all internal paths (_next) and api routes
		"/((?!_next|api).*)",
		// Optional: only run on root (/) URL
		// '/'
	],
};

---

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32596
  Available CPU cores: 12
Binaries:
  Node: 22.20.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 10.13.1
Relevant Packages:
  next: 16.0.0 // There is a newer version (16.0.1) available, upgrade 
recommended!
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rindev0901/learn-next-16

To Reproduce

  • Install dependencies (npm install or whatever).
  • Build and start project (npm run start or your equivalent).
  • Open the app in your browser
  • Check ternimal no any log in proxy

Current vs. Expected behavior

Current behavior

When i try access to / path in dev mode proxy work correct follow my below logic:

import { NextRequest, NextResponse } from "next/server";

export const locales = ["en", "nl"] as const;
export type Lang = (typeof locales)[number];

// Get the preferred locale, similar to the above or using a library
function getLocale(request: NextRequest) {
	console.log("Call proxy");
	const acceptLanguage = request.headers.get("accept-language");
	if (!acceptLanguage) return locales[0];

	const languages = acceptLanguage.split(",").map((lang) => lang.trim());
	const matchedLocale = languages.find((lang) =>
		locales.includes(lang as never)
	);
	return matchedLocale || locales[0];
}

export function proxy(request: NextRequest) {
	// Check if there is any supported locale in the pathname
	const { pathname } = request.nextUrl;
	const pathnameHasLocale = locales.some(
		(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
	);

	if (pathnameHasLocale) return;

	// Redirect if there is no locale
	const locale = getLocale(request);
	request.nextUrl.pathname = `/${locale}${pathname}`;
	// e.g. incoming request is /products
	// The new URL is now /en-US/products
	return NextResponse.redirect(request.nextUrl);
}

export const config = {
	matcher: [
		// Skip all internal paths (_next) and api routes
		"/((?!_next|api).*)",
		// Optional: only run on root (/) URL
		// '/'
	],
};

But after build and run in production mode the proxy is not running and I don't see any log lines displayed

Expected behavior

I want when the user accesses a path that does not contain locale, he will be redirected to the default locale.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32596
  Available CPU cores: 12
Binaries:
  Node: 22.20.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 10.13.1
Relevant Packages:
  next: 16.0.0 // There is a newer version (16.0.1) available, upgrade 
recommended!
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

No response

extent analysis

TL;DR

The issue can be resolved by upgrading to the latest version of Next.js, as the current version (16.0.) may have a bug that prevents the proxy from working in production mode.

Guidance

  • Check the Next.js documentation for any known issues with middleware in version 16..
  • Verify that the proxy function is being called in production mode by adding a log statement at the beginning of the function.
  • Try upgrading to the latest version of Next.js (

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING