From a6b27416e8907d0060419df7e8d75e1860ec7d86 Mon Sep 17 00:00:00 2001 From: yardend Date: Mon, 6 Jul 2026 18:59:03 +0300 Subject: [PATCH] chore(ai-gateway): drop the Base44-App-Base-Url header path connection() now always builds the gateway baseURL from serverUrl (Base44-Api-Url inside backend functions). The backend PR that injected Base44-App-Base-Url was closed, so the header never ships; the platform instead guarantees Base44-Api-Url resolves to the app on every invocation path. Removes the header read in createClientFromRequest, the appBaseUrl plumbing into the AI gateway module, and the related tests. The pre-existing appBaseUrl client config (auth login/logout URLs) is unchanged. Co-Authored-By: Claude Fable 5 --- src/client.ts | 6 ++---- src/modules/ai-gateway.ts | 4 +--- src/modules/ai-gateway.types.ts | 2 -- tests/unit/ai-gateway.test.ts | 28 ++-------------------------- 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/client.ts b/src/client.ts index feeab32..5b46e80 100644 --- a/src/client.ts +++ b/src/client.ts @@ -191,7 +191,7 @@ export function createClient(config: CreateClientConfig): Base44Client { serverUrl, token, }), - aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token }), + aiGateway: createAiGatewayModule({ serverUrl, token }), appLogs: createAppLogsModule(axiosClient, appId), users: createUsersModule(axiosClient, appId), analytics: createAnalyticsModule({ @@ -235,7 +235,7 @@ export function createClient(config: CreateClientConfig): Base44Client { serverUrl, token, }), - aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token: serviceToken }), + aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken }), appLogs: createAppLogsModule(serviceRoleAxiosClient, appId), cleanup: () => { if (socket) { @@ -395,7 +395,6 @@ export function createClientFromRequest(request: Request): Base44Client { ); const appId = request.headers.get("Base44-App-Id"); const serverUrlHeader = request.headers.get("Base44-Api-Url"); - const appBaseUrlHeader = request.headers.get("Base44-App-Base-Url"); const functionsVersion = request.headers.get("Base44-Functions-Version"); const stateHeader = request.headers.get("Base44-State"); @@ -443,7 +442,6 @@ export function createClientFromRequest(request: Request): Base44Client { return createClient({ serverUrl: serverUrlHeader || "https://base44.app", - appBaseUrl: appBaseUrlHeader ?? undefined, appId, token: userToken, serviceToken: serviceRoleToken, diff --git a/src/modules/ai-gateway.ts b/src/modules/ai-gateway.ts index e4c9be4..97a43bb 100644 --- a/src/modules/ai-gateway.ts +++ b/src/modules/ai-gateway.ts @@ -7,12 +7,10 @@ import { export function createAiGatewayModule({ serverUrl, - appBaseUrl, token, }: AiGatewayModuleConfig): AiGatewayModule { - const gatewayOrigin = appBaseUrl || serverUrl; const connection = (): AiGatewayConnection => ({ - baseURL: `${gatewayOrigin}/api/ai/openai/v1`, + baseURL: `${serverUrl}/api/ai/openai/v1`, token: token ?? getAccessToken() ?? "", }); diff --git a/src/modules/ai-gateway.types.ts b/src/modules/ai-gateway.types.ts index 899c31d..57aec70 100644 --- a/src/modules/ai-gateway.types.ts +++ b/src/modules/ai-gateway.types.ts @@ -19,8 +19,6 @@ export interface AiGatewayConnection { export interface AiGatewayModuleConfig { /** Server URL */ serverUrl?: string; - /** The app's own public base URL (e.g. https://my-app.base44.app). */ - appBaseUrl?: string; /** Authentication token */ token?: string; } diff --git a/tests/unit/ai-gateway.test.ts b/tests/unit/ai-gateway.test.ts index 0829a21..a016815 100644 --- a/tests/unit/ai-gateway.test.ts +++ b/tests/unit/ai-gateway.test.ts @@ -25,45 +25,21 @@ describe("AI Gateway Module", () => { }); }); - test("should prefer appBaseUrl over serverUrl (domain-resolved gateway)", () => { - const base44 = createClient({ - serverUrl, - appBaseUrl: "https://my-app.base44.app", - appId, - }); - expect(base44.aiGateway.connection().baseURL).toBe( - "https://my-app.base44.app/api/ai/openai/v1" - ); - }); - - test("should build from the Base44-App-Base-Url header in backend functions", () => { + test("should build from the Base44-Api-Url header in backend functions", () => { const request = new Request("https://functions.internal/run", { headers: { "Base44-App-Id": appId, "Base44-Api-Url": serverUrl, - "Base44-App-Base-Url": "https://my-app.base44.app", Authorization: "Bearer user-token", }, }); const base44 = createClientFromRequest(request); expect(base44.aiGateway.connection()).toEqual({ - baseURL: "https://my-app.base44.app/api/ai/openai/v1", + baseURL, token: "user-token", }); }); - test("should fall back to serverUrl when the app-base-url header is absent", () => { - const request = new Request("https://functions.internal/run", { - headers: { - "Base44-App-Id": appId, - "Base44-Api-Url": serverUrl, - Authorization: "Bearer user-token", - }, - }); - const base44 = createClientFromRequest(request); - expect(base44.aiGateway.connection().baseURL).toBe(baseURL); - }); - test("should use the service-role token via asServiceRole", () => { const base44 = createClient({ serverUrl,