8be3562c48
This makes sure that we detect the correct default locale for domain specific locales since a domain can have a different default locale residing at the root and we need to check this on the client for prerendered/auto-static pages. This also makes sure we disable the built-in redirect handling when on Vercel since it's handled already. Tests for this are tricky since we need to load the browser with a custom domain which requires editing the host file. Existing tests should ensure this doesn't break non-domain specific locale behavior though. This was also tested manually while testing https://github.com/vercel/vercel/pull/5298 x-ref: https://github.com/vercel/next.js/pull/17370
35 lines
722 B
TypeScript
35 lines
722 B
TypeScript
export function detectDomainLocale(
|
|
domainItems:
|
|
| Array<{
|
|
http?: boolean
|
|
domain: string
|
|
defaultLocale: string
|
|
}>
|
|
| undefined,
|
|
hostname?: string,
|
|
detectedLocale?: string
|
|
) {
|
|
let domainItem:
|
|
| {
|
|
http?: boolean
|
|
domain: string
|
|
defaultLocale: string
|
|
}
|
|
| undefined
|
|
|
|
if (domainItems) {
|
|
for (const item of domainItems) {
|
|
// remove port if present
|
|
const domainHostname = item.domain?.split(':')[0].toLowerCase()
|
|
if (
|
|
hostname === domainHostname ||
|
|
detectedLocale?.toLowerCase() === item.defaultLocale.toLowerCase()
|
|
) {
|
|
domainItem = item
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return domainItem
|
|
}
|