From 67326b738a26808f07eaad90c86e028402795c92 Mon Sep 17 00:00:00 2001 From: Till JS Date: Fri, 20 Mar 2026 17:11:31 +0100 Subject: [PATCH] fix(shared-api-client): add useRuntimeUrl flag for cross-app clients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getBaseUrl() always overrides baseUrl with window.__PUBLIC_BACKEND_URL__, which breaks cross-app API clients (e.g. calendar→todo, calendar→contacts) by routing all requests to the host app's backend. Added useRuntimeUrl: false option to skip the runtime override when the client already resolves its own base URL. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/calendar/apps/web/src/lib/api/birthdays.ts | 1 + apps/calendar/apps/web/src/lib/api/todos.ts | 1 + packages/shared-api-client/src/client.ts | 2 +- packages/shared-api-client/src/types.ts | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/calendar/apps/web/src/lib/api/birthdays.ts b/apps/calendar/apps/web/src/lib/api/birthdays.ts index 224712a90..d5e73627c 100644 --- a/apps/calendar/apps/web/src/lib/api/birthdays.ts +++ b/apps/calendar/apps/web/src/lib/api/birthdays.ts @@ -28,6 +28,7 @@ function getContactsClient() { getAuthToken: () => authStore.getValidToken(), timeout: 30000, debug: import.meta.env.DEV, + useRuntimeUrl: false, }); } return _contactsClient; diff --git a/apps/calendar/apps/web/src/lib/api/todos.ts b/apps/calendar/apps/web/src/lib/api/todos.ts index 4dea3385b..ba7891683 100644 --- a/apps/calendar/apps/web/src/lib/api/todos.ts +++ b/apps/calendar/apps/web/src/lib/api/todos.ts @@ -28,6 +28,7 @@ function getTodoClient() { getAuthToken: () => authStore.getValidToken(), timeout: 30000, debug: import.meta.env.DEV, + useRuntimeUrl: false, }); } return _todoClient; diff --git a/packages/shared-api-client/src/client.ts b/packages/shared-api-client/src/client.ts index 1dfe1b395..a0d5b7c23 100644 --- a/packages/shared-api-client/src/client.ts +++ b/packages/shared-api-client/src/client.ts @@ -61,7 +61,7 @@ export function createApiClient(config: ApiClientConfig): ApiClient { options: RequestOptions = {}, attemptNum = 0 ): Promise> { - const baseUrl = getBaseUrl(config.baseUrl); + const baseUrl = config.useRuntimeUrl !== false ? getBaseUrl(config.baseUrl) : config.baseUrl; const queryString = options.params ? buildQueryString(options.params) : ''; const url = baseUrl + apiPrefix + endpoint + queryString; const requestTimeout = options.timeout ?? timeout; diff --git a/packages/shared-api-client/src/types.ts b/packages/shared-api-client/src/types.ts index 1d39edfa7..96ceb14eb 100644 --- a/packages/shared-api-client/src/types.ts +++ b/packages/shared-api-client/src/types.ts @@ -62,6 +62,10 @@ export interface ApiClientConfig { /** Enable debug logging (default: false) */ debug?: boolean; + + /** Use window.__PUBLIC_BACKEND_URL__ runtime override (default: true). + * Set to false for cross-app clients that resolve their own base URL. */ + useRuntimeUrl?: boolean; } /**