From 6b23bfb39f3b45442060b8a4f02a50e4fdd91cf8 Mon Sep 17 00:00:00 2001 From: Katarina Date: Tue, 15 Jul 2025 18:12:46 +0200 Subject: [PATCH] Amend Upstream URL --- docker/entrypoint.sh | 6 +++--- nginx.conf.template | 2 +- public/config.template.js | 2 +- src/main.ts | 10 +++++++++- src/util/config.ts | 10 +++++----- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 41b6612..64c0b8e 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,19 +1,19 @@ #!/bin/sh set -e -: "${API_BASE_URL:=http://localhost}" +: "${API_HOST:=http://localhost}" : "${API_PORT:=7070}" # Create runtime config file in writable location cat > /runtime-config/config.js < /etc/nginx/nginx.conf fi diff --git a/nginx.conf.template b/nginx.conf.template index d55deeb..37be380 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -28,7 +28,7 @@ http { resolver 127.0.0.11 valid=10s ipv6=off; upstream backend { - server ${API_BASE_URL}:${API_PORT}; + server ${API_HOST}:${API_PORT}; } server { diff --git a/public/config.template.js b/public/config.template.js index 8567b56..7422919 100644 --- a/public/config.template.js +++ b/public/config.template.js @@ -1,4 +1,4 @@ window.__RUNTIME_CONFIG__ = { - API_BASE_URL: "__API_BASE_URL__", + API_HOST: "__API_HOST__", API_PORT: "__API_PORT__" }; \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 5cf97cb..020d7c6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -139,8 +139,16 @@ router.beforeEach(async (to) => { app.use(router); app.use(ToastService) +let apiUrl = getApiUrl(); + +if (!apiUrl) { + apiUrl = `http://${apiUrl}` +} else { + apiUrl = '' +} + const axiosInstance = axios.create({ - baseURL: getApiUrl() ?? '', + baseURL: apiUrl, headers: { 'Content-Type': 'application/json' } diff --git a/src/util/config.ts b/src/util/config.ts index ded12c0..5ad5376 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -1,11 +1,11 @@ export interface AppConfig { - API_BASE_URL: string; + API_HOST: string; API_PORT: number; } let runtimeConfig: AppConfig = { - API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '', - API_PORT: import.meta.env.VITE_API_BASE_URL || 8080 + API_HOST: import.meta.env.VITE_API_HOST || '', + API_PORT: import.meta.env.VITE_API_PORT || 8080 }; export function initConfig(config: Partial) { @@ -20,8 +20,8 @@ export function getConfig(): AppConfig { } export function getApiUrl() { - if (!runtimeConfig.API_BASE_URL) { + if (!runtimeConfig.API_HOST) { return null; } - return `${runtimeConfig.API_BASE_URL}:${runtimeConfig.API_PORT}`; + return `${runtimeConfig.API_HOST}:${runtimeConfig.API_PORT}`; } \ No newline at end of file