This commit is contained in:
+18
-4
@@ -28,6 +28,20 @@ type SiteRuntimeState = {
|
||||
maintenanceEnabled: boolean;
|
||||
};
|
||||
|
||||
function getSiteRuntimeStateOrigin(request: NextRequest): string {
|
||||
const configuredOrigin = process.env.SITE_RUNTIME_ORIGIN?.trim();
|
||||
|
||||
if (configuredOrigin) {
|
||||
return configuredOrigin;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return "http://127.0.0.1:3000";
|
||||
}
|
||||
|
||||
return request.nextUrl.origin;
|
||||
}
|
||||
|
||||
function getPathLocale(pathname: string, fallbackLocale: (typeof appLocales)[number]) {
|
||||
const locale = pathname.split("/")[1];
|
||||
|
||||
@@ -40,8 +54,8 @@ function isComingSoonPath(pathname: string) {
|
||||
|
||||
async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeState> {
|
||||
try {
|
||||
const runtimeStateUrl = new URL("/api/site/default-locale", request.url);
|
||||
const response = await fetch(new URL("/api/site/default-locale", request.url), {
|
||||
const runtimeStateUrl = new URL("/api/site/default-locale", getSiteRuntimeStateOrigin(request));
|
||||
const response = await fetch(runtimeStateUrl, {
|
||||
headers: {
|
||||
"x-middleware-request": "1",
|
||||
},
|
||||
@@ -74,8 +88,8 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
|
||||
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : FALLBACK_LOCALE,
|
||||
maintenanceEnabled: data.maintenanceEnabled === true,
|
||||
};
|
||||
} catch {
|
||||
console.error("middleware:getSiteRuntimeState:failed");
|
||||
} catch (error) {
|
||||
console.error("middleware:getSiteRuntimeState:failed", error);
|
||||
return {
|
||||
defaultLocale: FALLBACK_LOCALE,
|
||||
maintenanceEnabled: false,
|
||||
|
||||
Reference in New Issue
Block a user