wiki base, middleware
This commit is contained in:
parent
db1c07a3cf
commit
22ba0c7cf6
16 changed files with 2203 additions and 263 deletions
26
middleware.ts
Normal file
26
middleware.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue