diff --git a/flight-comparator/docker-compose.dev.yml b/flight-comparator/docker-compose.dev.yml new file mode 100644 index 0000000..49c5f57 --- /dev/null +++ b/flight-comparator/docker-compose.dev.yml @@ -0,0 +1,41 @@ +services: + backend: + build: + context: . + dockerfile: Dockerfile.backend + container_name: flight-radar-backend-dev + restart: unless-stopped + ports: + - "8000:8000" + environment: + - DATABASE_PATH=/app/data/cache.db + volumes: + # Mount source files so uvicorn --reload picks up changes + - ./api_server.py:/app/api_server.py + - ./airports.py:/app/airports.py + - ./cache.py:/app/cache.py + - ./database:/app/database + - flight-radar-data-dev:/app/data + command: uvicorn api_server:app --host 0.0.0.0 --port 8000 --reload + + frontend: + image: node:20-alpine + container_name: flight-radar-frontend-dev + working_dir: /app + restart: unless-stopped + ports: + - "5173:5173" + environment: + # Tells Vite's proxy where to find the backend inside Docker + - API_TARGET=http://backend:8000 + volumes: + - ./frontend:/app + # Isolate node_modules inside the container (don't use host's) + - /app/node_modules + command: sh -c "npm install && npm run dev -- --host" + depends_on: + - backend + +volumes: + flight-radar-data-dev: + driver: local diff --git a/flight-comparator/frontend/vite.config.ts b/flight-comparator/frontend/vite.config.ts index b6bafc5..25e94dc 100644 --- a/flight-comparator/frontend/vite.config.ts +++ b/flight-comparator/frontend/vite.config.ts @@ -1,20 +1,18 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +// When running inside Docker the backend is reachable via its service name. +// Outside Docker (plain `npm run dev`) it falls back to localhost. +const apiTarget = process.env.API_TARGET ?? 'http://localhost:8000' + // https://vite.dev/config/ export default defineConfig({ plugins: [react()], server: { port: 5173, proxy: { - '/api': { - target: 'http://localhost:8000', - changeOrigin: true, - }, - '/health': { - target: 'http://localhost:8000', - changeOrigin: true, - } + '/api': { target: apiTarget, changeOrigin: true }, + '/health': { target: apiTarget, changeOrigin: true }, } } })