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
+31
View File
@@ -39,6 +39,8 @@ function createMockRequest(url: string) {
describe("middleware locale runtime config", () => {
beforeEach(() => {
vi.resetModules();
process.env.NODE_ENV = "production";
delete process.env.SITE_RUNTIME_ORIGIN;
createMiddlewareMock.mockReset();
intlHandlerMock.mockReset();
intlHandlerMock.mockReturnValue(NextResponse.next());
@@ -66,6 +68,10 @@ describe("middleware locale runtime config", () => {
await middleware(request as never);
expect(fetch).toHaveBeenCalledWith(
new URL("http://127.0.0.1:3000/api/site/default-locale"),
expect.any(Object),
);
expect(createMiddlewareMock).toHaveBeenCalledTimes(1);
expect(createMiddlewareMock).toHaveBeenCalledWith(
expect.objectContaining({
@@ -115,4 +121,29 @@ describe("middleware locale runtime config", () => {
expect(response.headers.get("location")).toBe("https://example.com/coming-soon");
expect(intlHandlerMock).not.toHaveBeenCalled();
});
it("prefers the configured internal runtime origin when provided", async () => {
process.env.SITE_RUNTIME_ORIGIN = "http://app:3000";
vi.stubGlobal(
"fetch",
vi.fn(async () => ({
ok: true,
json: async () => ({
defaultLocale: "en",
maintenanceEnabled: false,
}),
})),
);
const { default: middleware } = await import("../middleware");
const request = createMockRequest("https://example.com/");
await middleware(request as never);
expect(fetch).toHaveBeenCalledWith(
new URL("http://app:3000/api/site/default-locale"),
expect.any(Object),
);
});
});