Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
fix: resolve API base URL per-request so Server Settings takes effect (#20)
Carter0c275516e2d0
diff --git a/.gitignore b/.gitignoreindex 858a024..e81be9d 100644--- a/.gitignore+++ b/.gitignore@@ -57,3 +57,4 @@ CLAUDE.md# Playwright artifactsweb/e2e/.auth/web/test-results/+.playwright-mcp/diff --git a/web/.env.example b/web/.env.exampleindex 29bbf02..b53db69 100644--- a/web/.env.example+++ b/web/.env.example@@ -1,2 +1,4 @@-# API Configuration-VITE_API_URL=http://localhost:3000/api+# API Configuration — optional.+# Leave unset for the standard deploy (nginx proxies /api to the backend).+# If set, it must be the full API base including the version segment.+# VITE_API_URL=http://localhost:3000/api/v1diff --git a/web/src/services/api.ts b/web/src/services/api.tsindex 56ca091..529cf17 100644--- a/web/src/services/api.ts+++ b/web/src/services/api.ts@@ -1,19 +1,21 @@import axios, { AxiosInstance } from 'axios'import * as types from '../types'-const getAPIBase = () => {+// Resolved per-request so the "Server settings" panel takes effect immediately,+// without needing a full page reload.+const resolveAPIBase = () => {+ const envUrl = import.meta.env.VITE_API_URL as string | undefined+ if (envUrl) return envUrlconst serverUrl = localStorage.getItem('server_url')return serverUrl ? `${serverUrl}/api/v1` : '/api/v1'}-const API_BASE = (import.meta.env.VITE_API_URL as string) || getAPIBase()-const api: AxiosInstance = axios.create({- baseURL: API_BASE,headers: { 'Content-Type': 'application/json' },})api.interceptors.request.use((config) => {+ config.baseURL = resolveAPIBase()const token = localStorage.getItem('access_token')if (token) config.headers.Authorization = `Bearer ${token}`return config@@ -27,7 +29,7 @@ api.interceptors.response.use(original._retry = truetry {const refreshToken = localStorage.getItem('refresh_token')- const res = await axios.post(`${API_BASE}/auth/refresh`, { refresh_token: refreshToken })+ const res = await axios.post(`${resolveAPIBase()}/auth/refresh`, { refresh_token: refreshToken })const newToken = res.data.data.tokenlocalStorage.setItem('access_token', newToken)original.headers.Authorization = `Bearer ${newToken}`