rsnext/packages/next/next-server/lib/i18n/detect-locale-cookie.ts
JJ Kasper 1eeac4f99b
Make sure locale detecting is case-insensitive (#17757)
Follow-up to https://github.com/vercel/next.js/pull/17370 this makes sure the locale detection is case-insensitive.
2020-10-11 20:40:47 +00:00

10 lines
355 B
TypeScript

import { IncomingMessage } from 'http'
export function detectLocaleCookie(req: IncomingMessage, locales: string[]) {
if (req.headers.cookie && req.headers.cookie.includes('NEXT_LOCALE')) {
const { NEXT_LOCALE } = (req as any).cookies
return locales.find(
(locale: string) => NEXT_LOCALE.toLowerCase() === locale.toLowerCase()
)
}
}