This commit is contained in:
eric
2026-03-11 23:10:18 -05:00
parent 26f1de5fb6
commit efe816915d
3 changed files with 9 additions and 6 deletions

29
proxy.ts Normal file
View File

@@ -0,0 +1,29 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const LOCALES = ["zh", "en"];
const DEFAULT_LOCALE = "zh";
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
const hasLocale = LOCALES.some(
(locale) => pathname === `/${locale}` || pathname.startsWith(`/${locale}/`)
);
if (hasLocale) {
return NextResponse.next();
}
if (pathname.startsWith("/_next") || pathname.startsWith("/api") || pathname.includes(".")) {
return NextResponse.next();
}
const locale = DEFAULT_LOCALE;
const newUrl = new URL(`/${locale}${pathname === "/" ? "" : pathname}`, request.url);
return NextResponse.redirect(newUrl);
}
export const config = {
matcher: ["/((?!_next|api|favicon.ico|.*\\..*).*)"],
};