diff --git a/heatmap-tool/backend/main.py b/heatmap-tool/backend/main.py index 2b42ff49..ffc08d76 100644 --- a/heatmap-tool/backend/main.py +++ b/heatmap-tool/backend/main.py @@ -44,6 +44,7 @@ def read_root(): @app.post("/api/upload") async def upload_file(file: UploadFile = File(...)): global df_storage, plz_column_name + print(f"--- Received request to /api/upload for file: {file.filename} ---") if not file.filename.endswith('.xlsx'): raise HTTPException(status_code=400, detail="Invalid file format. Please upload an .xlsx file.") @@ -77,16 +78,20 @@ async def upload_file(file: UploadFile = File(...)): df_storage = df + print(f"Successfully processed file. Found PLZ column: '{plz_column_name}'. Detected {len(filters)} filterable columns.") return {"filename": file.filename, "filters": filters, "plz_column": plz_column_name} except Exception as e: + print(f"ERROR processing file: {e}") raise HTTPException(status_code=500, detail=f"An error occurred while processing the file: {e}") @app.post("/api/heatmap") async def get_heatmap_data(request: FilterRequest): global df_storage, plz_column_name + print(f"--- Received request to /api/heatmap with filters: {request.filters} ---") if df_storage is None: + print("ERROR: No data in df_storage. File must be uploaded first.") raise HTTPException(status_code=404, detail="No data available. Please upload a file first.") try: @@ -117,7 +122,9 @@ async def get_heatmap_data(request: FilterRequest): "count": row["count"] }) + print(f"Generated heatmap data with {len(heatmap_data)} PLZ points.") return heatmap_data except Exception as e: + print(f"ERROR generating heatmap: {e}") raise HTTPException(status_code=500, detail=f"An error occurred while generating heatmap data: {e}") diff --git a/heatmap-tool/frontend/src/App.tsx b/heatmap-tool/frontend/src/App.tsx index f81e1530..45b3258d 100644 --- a/heatmap-tool/frontend/src/App.tsx +++ b/heatmap-tool/frontend/src/App.tsx @@ -36,7 +36,7 @@ function App() { setIsLoading(true); setError(null); try { - const response = await axios.post('http://backend:8000/api/heatmap', { + const response = await axios.post('/api/heatmap', { filters: selectedFilters, }); setHeatmapData(response.data); diff --git a/heatmap-tool/frontend/src/components/FileUpload.tsx b/heatmap-tool/frontend/src/components/FileUpload.tsx index 9afa667a..a50e39ef 100644 --- a/heatmap-tool/frontend/src/components/FileUpload.tsx +++ b/heatmap-tool/frontend/src/components/FileUpload.tsx @@ -39,7 +39,7 @@ const FileUpload: React.FC = ({ onUploadSuccess, setIsLoading, setError(null); try { - const response = await axios.post('http://backend:8000/api/upload', formData, { + const response = await axios.post('/api/upload', formData, { headers: { 'Content-Type': 'multipart/form-data', }, diff --git a/heatmap-tool/frontend/vite.config.ts b/heatmap-tool/frontend/vite.config.ts index 8b0f57b9..7fba83a1 100644 --- a/heatmap-tool/frontend/vite.config.ts +++ b/heatmap-tool/frontend/vite.config.ts @@ -4,4 +4,13 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api': { + target: 'http://backend:8000', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + } + } })