From 8960e40db43e791507b9515c8e8c341041821185 Mon Sep 17 00:00:00 2001 From: Amer Agovic Date: Sun, 10 May 2026 17:56:11 -0500 Subject: [PATCH] Support desktop API base URL override --- src/platform/api.js | 19 ++++++++++++++++++- src/platform/env.js | 24 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/platform/api.js b/src/platform/api.js index a6befe6..6275be9 100644 --- a/src/platform/api.js +++ b/src/platform/api.js @@ -52,6 +52,23 @@ class APIClient { ); } + /** + * Resolve an endpoint against the configured API base URL + * @param {string} endpoint + * @returns {string} + */ + resolveURL(endpoint = '') { + return `${this.baseURL}${endpoint}`; + } + + /** + * Replace the configured API base URL for future requests. + * @param {string} baseURL + */ + setBaseURL(baseURL = '/api') { + this.baseURL = baseURL || '/api'; + } + /** * Make API request * @param {string} endpoint @@ -59,7 +76,7 @@ class APIClient { * @returns {Promise} */ async request(endpoint, options = {}) { - const url = `${this.baseURL}${endpoint}`; + const url = this.resolveURL(endpoint); const config = this._applyRequestInterceptors({ ...options, headers: { diff --git a/src/platform/env.js b/src/platform/env.js index e876eaf..187e0f3 100644 --- a/src/platform/env.js +++ b/src/platform/env.js @@ -4,6 +4,7 @@ */ import { getProvider } from './storage.js'; +import { api as apiClient } from './api.js'; // Private storage instance for config const storage = getProvider('kv', 'config'); @@ -119,12 +120,31 @@ function resolveDevHostFlag(appConfig) { return false; } +function resolveDesktopApiBaseURL() { + if (typeof window === 'undefined') { + return null; + } + + const bridgeBase = window.__bfaceDesktop?.apiBaseUrl; + if (typeof bridgeBase === 'string' && bridgeBase.trim()) { + return bridgeBase.trim(); + } + + return null; +} + /** * Initialize environment config * @param {Object} appConfig - Configuration from profile */ export function initEnv(appConfig) { const api = appConfig.api || {}; + const resolvedApiBaseURL = + resolveDesktopApiBaseURL() + || appConfig.backend?.base_url + || api.base_url + || api.baseURL + || '/api'; config = { APP_NAME: appConfig.id || appConfig.name, APP_DISPLAY_NAME: appConfig.displayName || appConfig.short_name || appConfig.name, @@ -133,7 +153,7 @@ export function initEnv(appConfig) { THEME_COLOR: appConfig.theme_color || appConfig.themeColor || '#000000', UI_SHELL: appConfig.ui_shell || appConfig.uiShell || 'EmptyShell', STORAGE_BACKEND: appConfig.storage?.backend || 'localStorage', - API_BASE_URL: api.base_url || api.baseURL || '/api', + API_BASE_URL: resolvedApiBaseURL, MODULES: appConfig.modules || [], SECURITY_CONFIG: appConfig.security || {}, LOCALE: appConfig.locale || null, @@ -141,6 +161,7 @@ export function initEnv(appConfig) { // Store full profile for advanced access _profile: appConfig }; + apiClient.setBaseURL(resolvedApiBaseURL); } function resolveSystemLocale() { @@ -484,4 +505,3 @@ export function isProduction() { } return !isDevelopment(); } -