From 1bf0645c04e5c681de92aa3d6ea2fb318367f056 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 22 Apr 2026 20:21:20 +0200 Subject: [PATCH] Configure Vite dev proxy via VITE_BACKEND_URL --- Docs/Tasks.md | 2 +- Docs/Web-Development.md | 10 +++++++--- frontend/.env.example | 2 ++ frontend/vite.config.ts | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 frontend/.env.example diff --git a/Docs/Tasks.md b/Docs/Tasks.md index d71e108..e1878fe 100644 --- a/Docs/Tasks.md +++ b/Docs/Tasks.md @@ -595,7 +595,7 @@ Do **not** add a Content-Security-Policy meta tag; CSP should be set as an HTTP --- -### TASK-029 — Configure Vite proxy target via environment variable +### TASK-029 — Configure Vite proxy target via environment variable (done) **Where found:** `frontend/vite.config.ts` line 31 — `target: "http://backend:8000"` is a hardcoded Docker service hostname. diff --git a/Docs/Web-Development.md b/Docs/Web-Development.md index 1943ace..806fe85 100644 --- a/Docs/Web-Development.md +++ b/Docs/Web-Development.md @@ -135,9 +135,13 @@ frontend/ ``` > **Dev proxy target:** `vite.config.ts` proxies all `/api` requests to -> `http://backend:8000`. Use the compose **service name** (`backend`), not -> `localhost` — inside the container network `localhost` resolves to the -> frontend container itself and causes `ECONNREFUSED`. +> `http://backend:8000` by default. Set `VITE_BACKEND_URL` in `frontend/.env` +> or your shell to override the backend address for local development outside +> Docker. +> +> Use the compose **service name** (`backend`), not `localhost` — inside the +> container network `localhost` resolves to the frontend container itself and +> causes `ECONNREFUSED`. ### Separation of Concerns diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..eadae06 --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1,2 @@ +# Local frontend development without Docker +VITE_BACKEND_URL=http://localhost:8000 diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 1dfbfd3..ec2953f 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ // In the dev compose stack the backend is reachable via its service // name on the shared Docker/Podman network. Using "localhost" would // resolve to the frontend container itself and cause ECONNREFUSED. - target: "http://backend:8000", + target: process.env["VITE_BACKEND_URL"] ?? "http://backend:8000", changeOrigin: true, }, },