-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
23 lines (20 loc) · 820 Bytes
/
proxy.ts
File metadata and controls
23 lines (20 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const supportedLanguages = ["en", "de"];
export function proxy(request: NextRequest) {
const cookieLang = request.cookies.get("selectedLanguage")?.value;
let lang = "en";
if (cookieLang && supportedLanguages.includes(cookieLang)) {
lang = cookieLang;
} else {
const browserLang = request.headers.get("accept-language")?.toLowerCase() ?? "en";
if (browserLang.startsWith("de")) lang = "de";
}
const response = NextResponse.next();
response.headers.set("x-initial-language", lang);
response.headers.set("x-pathname", request.nextUrl.pathname);
return response;
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|assets|monitoring|robots.txt|sitemap.xml).*)"],
};