mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-17 19:29:40 +02:00
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:
parent
dea632c6c7
commit
67326b738a
4 changed files with 7 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ function getContactsClient() {
|
|||
getAuthToken: () => authStore.getValidToken(),
|
||||
timeout: 30000,
|
||||
debug: import.meta.env.DEV,
|
||||
useRuntimeUrl: false,
|
||||
});
|
||||
}
|
||||
return _contactsClient;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ function getTodoClient() {
|
|||
getAuthToken: () => authStore.getValidToken(),
|
||||
timeout: 30000,
|
||||
debug: import.meta.env.DEV,
|
||||
useRuntimeUrl: false,
|
||||
});
|
||||
}
|
||||
return _todoClient;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue