-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathproxy.ts
More file actions
31 lines (25 loc) · 978 Bytes
/
proxy.ts
File metadata and controls
31 lines (25 loc) · 978 Bytes
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
import { updateSession } from "@/utils/supabase/middleware";
import { type NextRequest } from "next/server";
import createIntlMiddleware from 'next-intl/middleware';
import { locales, defaultLocale } from './i18n';
const intlMiddleware = createIntlMiddleware({
locales,
defaultLocale,
localePrefix: 'always',
localeDetection: true
});
export default async function proxy(request: NextRequest) {
const country = request.headers.get('x-vercel-ip-country') || 'UNKNOWN';
const intlResponse = intlMiddleware(request);
intlResponse.headers.set('x-user-country', country);
const supabaseResponse = await updateSession(request);
supabaseResponse.cookies.getAll().forEach((cookie) => {
intlResponse.cookies.set(cookie.name, cookie.value);
});
return intlResponse;
}
export const config = {
matcher: [
'/((?!api|ffmpeg|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4|avif|webm|wasm|js)$).*)'
],
};