From 4b1b1f6e8d258842bb2c39e938ae7f3f5cc35037 Mon Sep 17 00:00:00 2001 From: Gaubee Date: Sun, 4 Jan 2026 14:08:14 +0800 Subject: [PATCH] fix(forge): use default API base URL instead of requiring env var - Use https://walletapi.bfmeta.info as default (same as other BioForest services) - Remove ApiConfigError class (no longer needed) - Still supports VITE_COT_API_BASE_URL override for flexibility --- miniapps/forge/src/api/client.ts | 4 +-- miniapps/forge/src/api/config.ts | 44 ++++++++------------------------ 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/miniapps/forge/src/api/client.ts b/miniapps/forge/src/api/client.ts index d115a19bc..98816d0eb 100644 --- a/miniapps/forge/src/api/client.ts +++ b/miniapps/forge/src/api/client.ts @@ -2,9 +2,7 @@ * API Client */ -import { getApiBaseUrlSafe, ApiConfigError } from './config' - -export { ApiConfigError } +import { getApiBaseUrlSafe } from './config' export class ApiError extends Error { constructor( diff --git a/miniapps/forge/src/api/config.ts b/miniapps/forge/src/api/config.ts index 3a19a9e32..0b1d8e9e5 100644 --- a/miniapps/forge/src/api/config.ts +++ b/miniapps/forge/src/api/config.ts @@ -1,46 +1,22 @@ /** * API Configuration - * - * IMPORTANT: Base URL must be configured via VITE_COT_API_BASE_URL environment variable. - * The COT Recharge API host has not been confirmed - do not use a hardcoded default. + * + * Default base URL is https://walletapi.bfmeta.info (same as other BioForest services). + * Can be overridden via VITE_COT_API_BASE_URL environment variable. */ -/** Configuration error for missing API base URL */ -export class ApiConfigError extends Error { - constructor() { - super( - '[Forge API] VITE_COT_API_BASE_URL is not configured. ' + - 'Please set this environment variable to the COT Recharge API base URL.' - ) - this.name = 'ApiConfigError' - } -} - -/** API Base URL - must be configured via environment variable */ -function getApiBaseUrl(): string { - const url = import.meta.env.VITE_COT_API_BASE_URL - if (!url) { - // Log error for visibility in dev tools - console.error(new ApiConfigError().message) - // Throw to fail fast - prevents silent failures with relative paths - throw new ApiConfigError() - } - return url -} +/** Default API Base URL (used by all BioForest chain services) */ +const DEFAULT_API_BASE_URL = 'https://walletapi.bfmeta.info' -// Lazy initialization to allow error handling at app level -let _apiBaseUrl: string | null = null +/** API Base URL - uses default or environment override */ +export const API_BASE_URL = + import.meta.env.VITE_COT_API_BASE_URL || DEFAULT_API_BASE_URL +/** Get API Base URL (for backwards compatibility) */ export function getApiBaseUrlSafe(): string { - if (_apiBaseUrl === null) { - _apiBaseUrl = getApiBaseUrl() - } - return _apiBaseUrl + return API_BASE_URL } -// For backwards compatibility - will throw if not configured -export const API_BASE_URL = import.meta.env.VITE_COT_API_BASE_URL || '' - /** API Endpoints */ export const API_ENDPOINTS = { /** 获取支持的充值配置 */