Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ services:
- "5173:5173"
depends_on:
- app
environment:
# Vite dev-server proxy target. Inside the compose network, the
# backend service is reachable at http://app:8000. The browser
# still hits http://localhost:5173/api/v1/* and Vite proxies it.
- VITE_API_PROXY_TARGET=http://app:8000
# Bind-mount the source so Vite HMR sees host edits. node_modules stays
# inside the container so platform-native deps aren't shadowed.
volumes:
Expand Down
19 changes: 19 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// `/api/*` calls from the React app are proxied to the FastAPI backend so
// the dev experience matches a same-origin production deployment. Without
// this Vite serves `index.html` for `/api/*`, which the browser then tries
// to JSON.parse — producing "Unexpected token '<'".
//
// Override the target via env when needed:
// - Local (no Docker): defaults to http://localhost:8000.
// - docker-compose: set VITE_API_PROXY_TARGET=http://app:8000 (inside
// the compose network the backend hostname is `app`).
const API_PROXY_TARGET = process.env.VITE_API_PROXY_TARGET ?? 'http://localhost:8000'

// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/api': {
target: API_PROXY_TARGET,
changeOrigin: true,
},
},
},
})
Loading