SPB Git

Repository Public

proxy.ts 858 B 23 lines typescript

1import { NextResponse, type NextRequest } from "next/server";23/**4 * Locale routing. English is canonical at the root, French under /fr.5 * Internally every public page lives under /[locale]; this rewrites /x to /en/x.6 */7const PASS = /^\/(api|media|studio|_next|fr)(\/|$)|\.[a-z0-9]+$|^\/(opengraph-image|icon|apple-icon)/i;89export function proxy(req: NextRequest) {10  const { pathname } = req.nextUrl;11  if (PASS.test(pathname)) return NextResponse.next();12  if (pathname === "/en" || pathname.startsWith("/en/")) {13    const url = req.nextUrl.clone();14    url.pathname = pathname.slice(3) || "/";15    return NextResponse.redirect(url, 308);16  }17  const url = req.nextUrl.clone();18  url.pathname = `/en${pathname === "/" ? "" : pathname}`;19  return NextResponse.rewrite(url);20}2122export const config = { matcher: ["/((?!_next/static|_next/image).*)"] };23
Files main
Menu

Theme