fix(frontend): drop localStorage HF_BACKEND_BASE_URL; env-only
api.ts + useAuthConfig kept the old wizard-era localStorage path for the backend URL, which is why fresh browsers saw blank pages on MonitorPage and any other api-using page after the v0.4.0 wizard removal — without the wizard pre-seeding localStorage, getApiBase() returned undefined and axios called same-origin (frontend nginx, 404). App.tsx getApiBase() partially worked because I had only refactored that one path; api.ts (used by everything else) still had its own duplicate getApiBase that I missed. This commit removes the localStorage path entirely from all 3 read sites (api.ts / App.tsx / useAuthConfig.ts) — single source of truth is now the build-time env baked in by the Dockerfile ARG. - src/services/api.ts: const API_BASE = import.meta.env.VITE_HF_BACKEND_BASE_URL - src/App.tsx: const API_BASE = ... (replaces getApiBase()) - src/hooks/useAuthConfig.ts: const BACKEND_BASE = ... - src/test/setup.ts: stub import.meta.env instead of localStorage key Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
src/App.tsx
19
src/App.tsx
@@ -23,17 +23,10 @@ import OidcCallbackPage from '@/pages/OidcCallbackPage'
|
||||
import OidcSettingsPage from '@/pages/OidcSettingsPage'
|
||||
import axios from 'axios'
|
||||
|
||||
// Backend URL is baked in at build time via VITE_HF_BACKEND_BASE_URL (the
|
||||
// docker-compose hf-frontend service passes it as a build ARG). Falling
|
||||
// back to a same-origin call only makes sense in dev with the Vite proxy.
|
||||
// localStorage override is kept as an escape hatch for one-off pointing
|
||||
// (e.g. dev pointing the prod build at a local backend).
|
||||
const getApiBase = (): string => {
|
||||
const ls = localStorage.getItem('HF_BACKEND_BASE_URL')
|
||||
if (ls) return ls
|
||||
const baked = import.meta.env.VITE_HF_BACKEND_BASE_URL
|
||||
return baked || ''
|
||||
}
|
||||
// Backend URL is baked in at build time via VITE_HF_BACKEND_BASE_URL
|
||||
// (docker build --build-arg). Empty string → same-origin call (only
|
||||
// works in dev with the Vite proxy).
|
||||
const API_BASE = import.meta.env.VITE_HF_BACKEND_BASE_URL || ''
|
||||
|
||||
type AppState = 'checking' | 'no-admin' | 'ready'
|
||||
|
||||
@@ -48,7 +41,7 @@ export default function App() {
|
||||
|
||||
const checkInitialized = async () => {
|
||||
try {
|
||||
const res = await axios.get(`${getApiBase()}/config/status`, { timeout: 5000 })
|
||||
const res = await axios.get(`${API_BASE}/config/status`, { timeout: 5000 })
|
||||
const cfg = res.data || {}
|
||||
if (cfg.initialized === true) {
|
||||
setAppState('ready')
|
||||
@@ -57,7 +50,7 @@ export default function App() {
|
||||
setAppState('no-admin')
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
setErrorMessage(`Backend unreachable at ${getApiBase() || '<same origin>'} — ${msg}`)
|
||||
setErrorMessage(`Backend unreachable at ${API_BASE || '<same origin>'} — ${msg}`)
|
||||
setAppState('no-admin')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user