Use internal origin for runtime locale state
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-15 08:33:27 +01:00
parent 4da093bb24
commit 635d54cb0e
3 changed files with 50 additions and 4 deletions
+18 -4
View File
@@ -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,