fix(shared-api-client): add useRuntimeUrl flag for cross-app clients

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) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-20 17:11:31 +01:00
parent dea632c6c7
commit 67326b738a
4 changed files with 7 additions and 1 deletions

View file

@ -28,6 +28,7 @@ function getContactsClient() {
getAuthToken: () => authStore.getValidToken(),
timeout: 30000,
debug: import.meta.env.DEV,
useRuntimeUrl: false,
});
}
return _contactsClient;

View file

@ -28,6 +28,7 @@ function getTodoClient() {
getAuthToken: () => authStore.getValidToken(),
timeout: 30000,
debug: import.meta.env.DEV,
useRuntimeUrl: false,
});
}
return _todoClient;

View file

@ -61,7 +61,7 @@ export function createApiClient(config: ApiClientConfig): ApiClient {
options: RequestOptions = {},
attemptNum = 0
): Promise<ApiResult<T>> {
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;

View file

@ -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;
}
/**