From 0f2152dc053d7f5d1a4a55daad4ac95ab5c91c7d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 26 Oct 2020 18:52:44 -0500 Subject: [PATCH] Add redirecting domain specific locales --- packages/now-next/src/index.ts | 15 ++++++++++++++- packages/now-next/src/utils.ts | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/now-next/src/index.ts b/packages/now-next/src/index.ts index 8850e45c6f5..f66c50c2a91 100644 --- a/packages/now-next/src/index.ts +++ b/packages/now-next/src/index.ts @@ -2021,13 +2021,26 @@ export const build = async ({ { // TODO: enable redirecting between domains, will require // updating the src with the desired locales to redirect - src: '/', + src: `^${path.join( + '/', + entryDirectory + )}/?(?:${i18n.locales + .map(locale => escapeStringRegexp(locale)) + .join('|')})?/?$`, locale: { redirect: i18n.domains.reduce( (prev: Record, item) => { prev[item.defaultLocale] = `http${ item.http ? '' : 's' }://${item.domain}/`; + + if (item.locales) { + item.locales.map(locale => { + prev[locale] = `http${item.http ? '' : 's'}://${ + item.domain + }/${locale}`; + }); + } return prev; }, {} diff --git a/packages/now-next/src/utils.ts b/packages/now-next/src/utils.ts index 2ccb2fb8ded..d47aa796dfd 100644 --- a/packages/now-next/src/utils.ts +++ b/packages/now-next/src/utils.ts @@ -332,6 +332,7 @@ export type RoutesManifest = { domains?: Array<{ http?: boolean; domain: string; + locales?: string[]; defaultLocale: string; }>; };