This commit is contained in:
+10
-9
@@ -2,7 +2,7 @@ import createMiddleware from "next-intl/middleware";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
import { appLocales, createI18nRouting, routing } from "./i18n/routing";
|
||||
import { appLocales, createI18nRouting } from "./i18n/routing";
|
||||
import {
|
||||
fromDevelopmentAdminPath,
|
||||
getAdminBaseUrl,
|
||||
@@ -14,7 +14,12 @@ import {
|
||||
isLegacyAdminPath,
|
||||
toInternalAdminPath,
|
||||
} from "./lib/admin-routing";
|
||||
import { getLocalizedPathWithDefault, stripLocalePrefix } from "./lib/locale";
|
||||
import {
|
||||
FALLBACK_LOCALE,
|
||||
getLocalizedPathWithDefault,
|
||||
isSupportedLocale,
|
||||
stripLocalePrefix,
|
||||
} from "./lib/locale";
|
||||
|
||||
const ADMIN_SESSION_COOKIE = "moh_admin_session";
|
||||
|
||||
@@ -23,10 +28,6 @@ type SiteRuntimeState = {
|
||||
maintenanceEnabled: boolean;
|
||||
};
|
||||
|
||||
function isSupportedLocale(locale: string | undefined): locale is (typeof appLocales)[number] {
|
||||
return locale === "ar" || locale === "en" || locale === "de";
|
||||
}
|
||||
|
||||
function getPathLocale(pathname: string, fallbackLocale: (typeof appLocales)[number]) {
|
||||
const locale = pathname.split("/")[1];
|
||||
|
||||
@@ -48,7 +49,7 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
defaultLocale: routing.defaultLocale,
|
||||
defaultLocale: FALLBACK_LOCALE,
|
||||
maintenanceEnabled: false,
|
||||
};
|
||||
}
|
||||
@@ -59,12 +60,12 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
|
||||
};
|
||||
|
||||
return {
|
||||
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : routing.defaultLocale,
|
||||
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : FALLBACK_LOCALE,
|
||||
maintenanceEnabled: data.maintenanceEnabled === true,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
defaultLocale: routing.defaultLocale,
|
||||
defaultLocale: FALLBACK_LOCALE,
|
||||
maintenanceEnabled: false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user