fix([2fd88f42]): implement vite proxy for robust API calls and add logging
This commit is contained in:
@@ -44,6 +44,7 @@ def read_root():
|
|||||||
@app.post("/api/upload")
|
@app.post("/api/upload")
|
||||||
async def upload_file(file: UploadFile = File(...)):
|
async def upload_file(file: UploadFile = File(...)):
|
||||||
global df_storage, plz_column_name
|
global df_storage, plz_column_name
|
||||||
|
print(f"--- Received request to /api/upload for file: {file.filename} ---")
|
||||||
if not file.filename.endswith('.xlsx'):
|
if not file.filename.endswith('.xlsx'):
|
||||||
raise HTTPException(status_code=400, detail="Invalid file format. Please upload an .xlsx file.")
|
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
|
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}
|
return {"filename": file.filename, "filters": filters, "plz_column": plz_column_name}
|
||||||
|
|
||||||
except Exception as e:
|
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}")
|
raise HTTPException(status_code=500, detail=f"An error occurred while processing the file: {e}")
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/heatmap")
|
@app.post("/api/heatmap")
|
||||||
async def get_heatmap_data(request: FilterRequest):
|
async def get_heatmap_data(request: FilterRequest):
|
||||||
global df_storage, plz_column_name
|
global df_storage, plz_column_name
|
||||||
|
print(f"--- Received request to /api/heatmap with filters: {request.filters} ---")
|
||||||
if df_storage is None:
|
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.")
|
raise HTTPException(status_code=404, detail="No data available. Please upload a file first.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -117,7 +122,9 @@ async def get_heatmap_data(request: FilterRequest):
|
|||||||
"count": row["count"]
|
"count": row["count"]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
print(f"Generated heatmap data with {len(heatmap_data)} PLZ points.")
|
||||||
return heatmap_data
|
return heatmap_data
|
||||||
|
|
||||||
except Exception as e:
|
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}")
|
raise HTTPException(status_code=500, detail=f"An error occurred while generating heatmap data: {e}")
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ function App() {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('http://backend:8000/api/heatmap', {
|
const response = await axios.post('/api/heatmap', {
|
||||||
filters: selectedFilters,
|
filters: selectedFilters,
|
||||||
});
|
});
|
||||||
setHeatmapData(response.data);
|
setHeatmapData(response.data);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const FileUpload: React.FC<FileUploadProps> = ({ onUploadSuccess, setIsLoading,
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('http://backend:8000/api/upload', formData, {
|
const response = await axios.post('/api/upload', formData, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,4 +4,13 @@ import react from '@vitejs/plugin-react'
|
|||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://backend:8000',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user