's'
This commit is contained in:
29
proxy.ts
Normal file
29
proxy.ts
Normal 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|.*\\..*).*)"],
|
||||
};
|
||||
Reference in New Issue
Block a user