From c7874f26780050beb7a122db01f60dbc1354ebbf Mon Sep 17 00:00:00 2001 From: Sven laptop Date: Wed, 6 May 2026 14:39:37 +0200 Subject: [PATCH] fixed api variable Co-authored-by: Copilot --- admin_ui/src/api.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/admin_ui/src/api.js b/admin_ui/src/api.js index 740e4f1..e09d7fd 100644 --- a/admin_ui/src/api.js +++ b/admin_ui/src/api.js @@ -1,8 +1,19 @@ import axios from 'axios' const RUNTIME = typeof window !== 'undefined' && window.__ENV__ ? window.__ENV__ : {} -const AUTH_API = RUNTIME.AUTH_API || import.meta.env.VITE_AUTH_API || 'http://localhost:5000' -const TRANSIT_API = RUNTIME.TRANSIT_API || import.meta.env.VITE_TRANSIT_API || 'http://localhost:5001' + +const normalizeApiBaseUrl = (value, fallbackPath) => { + const rawValue = value || '' + if (!rawValue) return fallbackPath + if (/^https?:\/\//i.test(rawValue) || rawValue.startsWith('//') || rawValue.startsWith('/')) { + return rawValue + } + + return `${window.location.protocol}//${rawValue}` +} + +const AUTH_API = normalizeApiBaseUrl(RUNTIME.AUTH_API || import.meta.env.VITE_AUTH_API, 'http://localhost:5000') +const TRANSIT_API = normalizeApiBaseUrl(RUNTIME.TRANSIT_API || import.meta.env.VITE_TRANSIT_API, 'http://localhost:5001') export const authClient = axios.create({ baseURL: AUTH_API }) export const transitClient = (token) => axios.create({