File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ services:
3030 - " 5173:5173"
3131 depends_on :
3232 - app
33+ environment :
34+ # Vite dev-server proxy target. Inside the compose network, the
35+ # backend service is reachable at http://app:8000. The browser
36+ # still hits http://localhost:5173/api/v1/* and Vite proxies it.
37+ - VITE_API_PROXY_TARGET=http://app:8000
3338 # Bind-mount the source so Vite HMR sees host edits. node_modules stays
3439 # inside the container so platform-native deps aren't shadowed.
3540 volumes :
Original file line number Diff line number Diff line change 11import { defineConfig } from 'vite'
22import react from '@vitejs/plugin-react'
33
4+ // `/api/*` calls from the React app are proxied to the FastAPI backend so
5+ // the dev experience matches a same-origin production deployment. Without
6+ // this Vite serves `index.html` for `/api/*`, which the browser then tries
7+ // to JSON.parse — producing "Unexpected token '<'".
8+ //
9+ // Override the target via env when needed:
10+ // - Local (no Docker): defaults to http://localhost:8000.
11+ // - docker-compose: set VITE_API_PROXY_TARGET=http://app:8000 (inside
12+ // the compose network the backend hostname is `app`).
13+ const API_PROXY_TARGET = process . env . VITE_API_PROXY_TARGET ?? 'http://localhost:8000'
14+
415// https://vite.dev/config/
516export default defineConfig ( {
617 plugins : [ react ( ) ] ,
18+ server : {
19+ proxy : {
20+ '/api' : {
21+ target : API_PROXY_TARGET ,
22+ changeOrigin : true ,
23+ } ,
24+ } ,
25+ } ,
726} )
You can’t perform that action at this time.
0 commit comments