-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update redirect handling for locale domains (#17856)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9300151
commit 9a5a152
Showing
8 changed files
with
191 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/next/next-server/lib/i18n/detect-domain-locale.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { IncomingMessage } from 'http' | ||
|
||
export function detectDomainLocale( | ||
domainItems: | ||
| Array<{ | ||
http?: boolean | ||
domain: string | ||
defaultLocale: string | ||
}> | ||
| undefined, | ||
req?: IncomingMessage, | ||
detectedLocale?: string | ||
) { | ||
let domainItem: | ||
| { | ||
http?: boolean | ||
domain: string | ||
defaultLocale: string | ||
} | ||
| undefined | ||
|
||
if (domainItems) { | ||
const { host } = req?.headers || {} | ||
// remove port from host and remove port if present | ||
const hostname = host?.split(':')[0].toLowerCase() | ||
|
||
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 | ||
} |
37 changes: 0 additions & 37 deletions
37
packages/next/next-server/lib/i18n/detect-domain-locales.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.