Skip to content

armgit / lyftr

Public Imported from GitHub
0

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/.gitignore
index 858a024..e81be9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,3 +57,4 @@ CLAUDE.md
# Playwright artifacts
web/e2e/.auth/
web/test-results/
+.playwright-mcp/
diff --git a/web/.env.example b/web/.env.example
index 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/v1
diff --git a/web/src/services/api.ts b/web/src/services/api.ts
index 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 envUrl
const 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 = true
try {
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.token
localStorage.setItem('access_token', newToken)
original.headers.Authorization = `Bearer ${newToken}`