import { NextResponse, NextRequest } from 'next/server'; import { routing } from '@/i18n/routing'; export const config = { matcher: [ "/((?!api|_next|.*\\..*).*)" ] }; // Proxy für geschützte Routen + i18n + Cookies export async function proxy(request: NextRequest) { const locale = routing.locales.find(locale => request.nextUrl.pathname.startsWith(`/${locale}`) ); if (!locale) { const newLang = request.headers .get('accept-language') ?.split(',')[0] ?.split('-')[0] ?? 'en'; const redirect = `/${newLang}` + request.nextUrl.pathname + request.nextUrl.search; return NextResponse.redirect(new URL(redirect, request.url)); } const headers = new Headers(); headers.set('X-NEXT-INTL-LOCALE', locale); return NextResponse.next({ request: { headers } }); }