Support desktop API base URL override
This commit is contained in:
+18
-1
@@ -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
|
* Make API request
|
||||||
* @param {string} endpoint
|
* @param {string} endpoint
|
||||||
@@ -59,7 +76,7 @@ class APIClient {
|
|||||||
* @returns {Promise<Response>}
|
* @returns {Promise<Response>}
|
||||||
*/
|
*/
|
||||||
async request(endpoint, options = {}) {
|
async request(endpoint, options = {}) {
|
||||||
const url = `${this.baseURL}${endpoint}`;
|
const url = this.resolveURL(endpoint);
|
||||||
const config = this._applyRequestInterceptors({
|
const config = this._applyRequestInterceptors({
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
+22
-2
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getProvider } from './storage.js';
|
import { getProvider } from './storage.js';
|
||||||
|
import { api as apiClient } from './api.js';
|
||||||
|
|
||||||
// Private storage instance for config
|
// Private storage instance for config
|
||||||
const storage = getProvider('kv', 'config');
|
const storage = getProvider('kv', 'config');
|
||||||
@@ -119,12 +120,31 @@ function resolveDevHostFlag(appConfig) {
|
|||||||
return false;
|
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
|
* Initialize environment config
|
||||||
* @param {Object} appConfig - Configuration from profile
|
* @param {Object} appConfig - Configuration from profile
|
||||||
*/
|
*/
|
||||||
export function initEnv(appConfig) {
|
export function initEnv(appConfig) {
|
||||||
const api = appConfig.api || {};
|
const api = appConfig.api || {};
|
||||||
|
const resolvedApiBaseURL =
|
||||||
|
resolveDesktopApiBaseURL()
|
||||||
|
|| appConfig.backend?.base_url
|
||||||
|
|| api.base_url
|
||||||
|
|| api.baseURL
|
||||||
|
|| '/api';
|
||||||
config = {
|
config = {
|
||||||
APP_NAME: appConfig.id || appConfig.name,
|
APP_NAME: appConfig.id || appConfig.name,
|
||||||
APP_DISPLAY_NAME: appConfig.displayName || appConfig.short_name || 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',
|
THEME_COLOR: appConfig.theme_color || appConfig.themeColor || '#000000',
|
||||||
UI_SHELL: appConfig.ui_shell || appConfig.uiShell || 'EmptyShell',
|
UI_SHELL: appConfig.ui_shell || appConfig.uiShell || 'EmptyShell',
|
||||||
STORAGE_BACKEND: appConfig.storage?.backend || 'localStorage',
|
STORAGE_BACKEND: appConfig.storage?.backend || 'localStorage',
|
||||||
API_BASE_URL: api.base_url || api.baseURL || '/api',
|
API_BASE_URL: resolvedApiBaseURL,
|
||||||
MODULES: appConfig.modules || [],
|
MODULES: appConfig.modules || [],
|
||||||
SECURITY_CONFIG: appConfig.security || {},
|
SECURITY_CONFIG: appConfig.security || {},
|
||||||
LOCALE: appConfig.locale || null,
|
LOCALE: appConfig.locale || null,
|
||||||
@@ -141,6 +161,7 @@ export function initEnv(appConfig) {
|
|||||||
// Store full profile for advanced access
|
// Store full profile for advanced access
|
||||||
_profile: appConfig
|
_profile: appConfig
|
||||||
};
|
};
|
||||||
|
apiClient.setBaseURL(resolvedApiBaseURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSystemLocale() {
|
function resolveSystemLocale() {
|
||||||
@@ -484,4 +505,3 @@ export function isProduction() {
|
|||||||
}
|
}
|
||||||
return !isDevelopment();
|
return !isDevelopment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user