From e75dbf3080c42e808a58b9f637f449825f2a73d3 Mon Sep 17 00:00:00 2001
From: Leah Tacke genannt Unterberg <leah.tgu@pads.rwth-aachen.de>
Date: Thu, 31 Oct 2024 11:15:30 +0100
Subject: [PATCH] cleaning up environment variable configuration

---
 .env.production     | 3 ++-
 Dockerfile          | 4 +++-
 nginx.conf.template | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/.env.production b/.env.production
index fceb51e..b01dfd8 100644
--- a/.env.production
+++ b/.env.production
@@ -1,5 +1,6 @@
-API_PREFIX=/api
+API_BASE=backend
 API_PORT=8080
+API_PREFIX=/api
 FRONTEND_PORT=8090
 VITE_FRONTEND_PORT=$FRONTEND_PORT
 VITE_API_PREFIX=$API_PREFIX
diff --git a/Dockerfile b/Dockerfile
index 67ab9c5..48e7eb0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,14 +10,16 @@ RUN npm run build -- --mode production
 FROM nginx:stable-alpine AS production-stage
 ARG FRONTEND_PORT=8090
 ARG API_PORT=8080
+ARG API_BASE=backend
 ARG API_PREFIX=/api
 ENV FRONTEND_PORT=$FRONTEND_PORT
+ENV API_BASE=$API_BASE
 ENV API_PORT=$API_PORT
 ENV API_PREFIX=$API_PREFIX
 
 COPY --from=build-stage /app/dist /usr/share/nginx/html
 COPY nginx.conf.template /etc/nginx/conf.d/default.conf.template
-RUN envsubst '\$API_PORT \$FRONTEND_PORT \$API_PREFIX' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
+RUN envsubst '\$API_BASE \$API_PORT \$FRONTEND_PORT \$API_PREFIX' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
 RUN cat /etc/nginx/conf.d/default.conf
 EXPOSE $FRONTEND_PORT
 CMD ["nginx", "-g", "daemon off;"]
\ No newline at end of file
diff --git a/nginx.conf.template b/nginx.conf.template
index d907b71..e3715ca 100644
--- a/nginx.conf.template
+++ b/nginx.conf.template
@@ -1,5 +1,5 @@
 upstream api {
-    server backend:${API_PORT};
+    server ${API_BASE}:${API_PORT};
 }
 
 server {
-- 
GitLab