From 2d5988552fb91352026b43e6e76330ba6a3b55b7 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sun, 20 Apr 2025 20:29:34 +0200 Subject: [PATCH] chore(frontend): Configureerbare API URL --- frontend/src/config.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/config.ts b/frontend/src/config.ts index 53d6f253..60a63db4 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,8 +1,16 @@ export const apiConfig = { - baseUrl: - window.location.hostname === "localhost" && !(window.location.port === "80" || window.location.port === "") - ? "http://localhost:3000/api" - : window.location.origin + "/api", + baseUrl: ((): string => { + if (import.meta.env.VITE_API_BASE_URL) { + return import.meta.env.VITE_API_BASE_URL; + } + + if (window.location.hostname === "localhost" && !(window.location.port === "80" || window.location.port === "")) { + return "http://localhost:3000/api"; + } + + // Fallback to the current origin with "/api" suffix + return `${window.location.origin}/api`; + })(), }; export const loginRoute = "/login";