From c70d0d0300176ed570058335a5c2235a52e42387 Mon Sep 17 00:00:00 2001 From: Marcin-Ramotowski Date: Tue, 29 Apr 2025 09:12:34 +0000 Subject: [PATCH] Configured frontend during image build --- README.md | 4 ++++ frontend/frontend.dockerfile | 2 +- frontend/src/api/api.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2926616..7b0234a 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ Poniżej lista zmiennych środowiskowych dla backendu: | `TODOLIST_ADMIN_PASSWORD` | ❌ | Hasło domyślnego administratora aplikacji (zalecane). | | `FRONTEND_ORIGIN` | ✅ | Adres URL frontendu (np. `http://localhost:5173`) do ustawienia CORS/cookies (wymagany do połączenia frontendu z API, można podać więcej adresów rozdzielając je przecinkiem) | +Poniżej lista zmiennych środowiskowych dla frontendu: +| Nazwa | Wymagana | Opis | +| ------------------------- | -------- | ------------------------------------------------------------------------------------------------ | +| `VITE_API_URL` | ✅ | Adres URL backendu, z którym komunikuje się frontend. Ustawiany w pliku `frontend/frontend.dockerfile` przed zbudowaniem kontenera. | --- ## 📅 Dalsze kroki diff --git a/frontend/frontend.dockerfile b/frontend/frontend.dockerfile index 5c0601d..2c6fa0c 100644 --- a/frontend/frontend.dockerfile +++ b/frontend/frontend.dockerfile @@ -4,7 +4,7 @@ WORKDIR /app COPY package*.json ./ RUN npm install COPY . . -RUN npm run build +RUN VITE_API_URL="http://localhost:5000" npm run build # Etap 2: Nginx FROM nginx:alpine diff --git a/frontend/src/api/api.ts b/frontend/src/api/api.ts index a9d3399..47adb3f 100644 --- a/frontend/src/api/api.ts +++ b/frontend/src/api/api.ts @@ -1,7 +1,7 @@ import axios from "axios"; import Cookies from "js-cookie"; -const API_URL = "http://localhost:5000"; +const API_URL = import.meta.env.VITE_API_URL; const api = axios.create({ baseURL: API_URL,