wiki base, middleware

This commit is contained in:
3zachm 2023-02-06 03:03:33 -08:00
parent db1c07a3cf
commit 22ba0c7cf6
16 changed files with 2203 additions and 263 deletions

26
middleware.ts Normal file
View file

@ -0,0 +1,26 @@
import { NextRequest, NextResponse } from "next/server";
const PUBLIC_FILE = /\.(.*)$/;
export async function middleware(req: NextRequest) {
if (
req.nextUrl.pathname.startsWith("/_next") ||
req.nextUrl.pathname.includes("/api/") ||
PUBLIC_FILE.test(req.nextUrl.pathname)
) {
return;
}
// if path is /wiki/, redirect to /wiki/:locale
if (req.nextUrl.pathname === "/wiki") {
const language =
req.headers
.get("accept-language")
?.split(",")?.[0]
.split("-")?.[0]
.toLowerCase() || "en";
const redirUrl = req.nextUrl.clone();
redirUrl.pathname = redirUrl.pathname + `/${language}`;
return NextResponse.rewrite(redirUrl);
}
return;
}