diff --git a/src/App.tsx b/src/App.tsx index 8d7c061..f489fed 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -33,7 +33,11 @@ export default function App() { const res = await axios.get(`${WIZARD_BASE}/api/v1/config/harborforge.json`, { timeout: 5000, }) - if (res.data && res.data.initialized === true) { + const cfg = res.data || {} + if (cfg.backend_url) { + localStorage.setItem('HF_BACKEND_BASE_URL', cfg.backend_url) + } + if (cfg.initialized === true) { setAppState('ready') } else { setAppState('setup') diff --git a/src/pages/SetupWizardPage.tsx b/src/pages/SetupWizardPage.tsx index 9f10924..49a40e5 100644 --- a/src/pages/SetupWizardPage.tsx +++ b/src/pages/SetupWizardPage.tsx @@ -92,6 +92,10 @@ export default function SetupWizardPage({ wizardBase, onComplete }: Props) { headers: { 'Content-Type': 'application/json' }, }) + if (form.backend_base_url) { + localStorage.setItem('HF_BACKEND_BASE_URL', form.backend_base_url) + } + setStep(4) } catch (err: any) { setError(`保存配置失败: ${err.message}`) diff --git a/src/services/api.ts b/src/services/api.ts index 4814c5b..0cd7b30 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,10 +1,15 @@ import axios from 'axios' +const getApiBase = () => { + return localStorage.getItem('HF_BACKEND_BASE_URL') || import.meta.env.VITE_API_BASE || 'http://127.0.0.1:8000' +} + const api = axios.create({ - baseURL: import.meta.env.VITE_API_BASE || '/api', + baseURL: getApiBase(), }) api.interceptors.request.use((config) => { + config.baseURL = getApiBase() const token = localStorage.getItem('token') if (token) { config.headers.Authorization = `Bearer ${token}`