forked from hackclub/site
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.ts
More file actions
36 lines (29 loc) 路 1.08 KB
/
Copy pathproxy.ts
File metadata and controls
36 lines (29 loc) 路 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import createMiddleware from "next-intl/middleware";
import type { NextRequest, NextResponse } from "next/server";
import { routing } from "./i18n/routing";
const handleI18n = createMiddleware(routing);
/** Attach request headers so Server Components can read them via `headers()`. */
function withRequestHeaders(response: NextResponse, headers: Record<string, string>) {
const override = new Set(
(response.headers.get("x-middleware-override-headers") ?? "")
.split(",")
.map((h) => h.trim())
.filter(Boolean),
);
for (const [key, value] of Object.entries(headers)) {
override.add(key);
response.headers.set(`x-middleware-request-${key}`, value);
}
response.headers.set("x-middleware-override-headers", Array.from(override).join(","));
return response;
}
export default function proxy(request: NextRequest) {
const response = handleI18n(request);
return withRequestHeaders(response, {
"x-pathname": request.nextUrl.pathname,
"x-search": request.nextUrl.search,
});
}
export const config = {
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
};