fix(admin-ui): backlog sweep — 7 review items

This commit is contained in:
Александр Зимин
2026-05-10 19:21:33 +00:00
parent c7f6559bed
commit 48dd8a487a
6 changed files with 156 additions and 16 deletions
+21 -1
View File
@@ -36,8 +36,28 @@ export const setUnauthorizedHandler = (h: Unauthorized401Handler | null): void =
unauthorizedHandler = h
}
/**
* baseURL построение:
* - Если VITE_API_BASE задан и заканчивается на /api/v1 (или содержит api/) —
* используем как есть.
* - Если VITE_API_BASE задан без api-prefix (e.g. https://api.example.com) —
* автоматически добавляем `/api/v1` суффикс.
* - Default: `/api/v1` (relative — admin-ui nginx proxies to writer/read-api).
*
* Раньше ambiguous — если кто-то задал `VITE_API_BASE=https://api.example.com`
* без `/v1`, все запросы становились `/dictionaries` относительно корня
* (правильно `/api/v1/dictionaries`). Теперь fall-through к expected layout.
*/
const buildBaseURL = (): string => {
const env = import.meta.env.VITE_API_BASE
if (!env) return '/api/v1'
const trimmed = env.replace(/\/+$/, '')
if (/\/api(\/|$)/i.test(trimmed)) return trimmed
return `${trimmed}/api/v1`
}
export const apiClient = axios.create({
baseURL: import.meta.env.VITE_API_BASE ?? '/api/v1',
baseURL: buildBaseURL(),
timeout: 10_000,
})