Fix locale redirect staying on majdtrading.com instead of localhost.
Next.js builds nextUrl from the PM2 bind address (127.0.0.1:3024), so an absolute redirect sent browsers to https://localhost:3024/fa. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
02aaf61bb6
commit
7034deda89
+6
-3
@@ -16,9 +16,12 @@ export function middleware(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
if (hasLocale || PUBLIC_FILE.test(pathname)) return NextResponse.next();
|
if (hasLocale || PUBLIC_FILE.test(pathname)) return NextResponse.next();
|
||||||
|
|
||||||
const url = request.nextUrl.clone();
|
// Relative Location keeps the public host; NextURL.origin is the PM2 bind address.
|
||||||
url.pathname = `/${defaultLocale}${pathname === "/" ? "" : pathname}`;
|
const location = `/${defaultLocale}${pathname === "/" ? "" : pathname}${request.nextUrl.search}`;
|
||||||
return NextResponse.redirect(url);
|
return new NextResponse(null, {
|
||||||
|
status: 307,
|
||||||
|
headers: { Location: location },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
|
|||||||
Reference in New Issue
Block a user