Configure Vite dev proxy via VITE_BACKEND_URL
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
2
frontend/.env.example
Normal file
2
frontend/.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
# Local frontend development without Docker
|
||||
VITE_BACKEND_URL=http://localhost:8000
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user