diff --git a/proxy.ts b/proxy.ts index ae35447..6beee82 100644 --- a/proxy.ts +++ b/proxy.ts @@ -14,12 +14,18 @@ export async function proxy(request: NextRequest) { ); if (!locale) { - const newLang = + let newLang = request.headers .get('accept-language') ?.split(',')[0] - ?.split('-')[0] - ?? 'en'; + ?.split('-')[0]; + + if (!newLang) + newLang = routing.defaultLocale; + else { + const langAvailable = (routing.locales as readonly string[]).includes(newLang); + if (!langAvailable) newLang = routing.defaultLocale; + } const redirect = `/${newLang}` + request.nextUrl.pathname