File size: 662 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import type { DomainLocale } from '../../../server/config-shared'

export function detectDomainLocale(
  domainItems?: readonly DomainLocale[],
  hostname?: string,
  detectedLocale?: string
) {
  if (!domainItems) return

  if (detectedLocale) {
    detectedLocale = detectedLocale.toLowerCase()
  }

  for (const item of domainItems) {
    // remove port if present
    const domainHostname = item.domain?.split(':', 1)[0].toLowerCase()
    if (
      hostname === domainHostname ||
      detectedLocale === item.defaultLocale.toLowerCase() ||
      item.locales?.some((locale) => locale.toLowerCase() === detectedLocale)
    ) {
      return item
    }
  }
}