Spaces:
Running
Running
Scribbler310 commited on
Commit ·
593c3ba
1
Parent(s): f93287b
Fix: White screen error and relative API paths
Browse files- backend/main.py +11 -7
- frontend/src/apiConfig.js +1 -1
backend/main.py
CHANGED
|
@@ -263,21 +263,25 @@ def chat_with_bot(req: ChatRequest):
|
|
| 263 |
FRONTEND_PATH = os.path.join(BASE_DIR, "..", "frontend", "dist")
|
| 264 |
|
| 265 |
if os.path.exists(FRONTEND_PATH):
|
| 266 |
-
# Mount the static files (CSS, JS, images)
|
| 267 |
-
app.mount("/static", StaticFiles(directory=FRONTEND_PATH), name="static")
|
| 268 |
-
|
| 269 |
-
# Catch-all route to serve the React index.html for any non-API route
|
| 270 |
@app.get("/{full_path:path}")
|
| 271 |
async def serve_frontend(full_path: str):
|
| 272 |
-
#
|
| 273 |
-
if full_path.startswith("api
|
| 274 |
return {"detail": "Not Found"}
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
index_file = os.path.join(FRONTEND_PATH, "index.html")
|
| 277 |
if os.path.exists(index_file):
|
| 278 |
return FileResponse(index_file)
|
|
|
|
| 279 |
return {"detail": "Frontend build not found"}
|
| 280 |
else:
|
| 281 |
@app.get("/")
|
| 282 |
def read_root():
|
| 283 |
return {"message": "Wafer Defect API is running. Frontend build folder not found."}
|
|
|
|
|
|
| 263 |
FRONTEND_PATH = os.path.join(BASE_DIR, "..", "frontend", "dist")
|
| 264 |
|
| 265 |
if os.path.exists(FRONTEND_PATH):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
@app.get("/{full_path:path}")
|
| 267 |
async def serve_frontend(full_path: str):
|
| 268 |
+
# 1. Skip API routes
|
| 269 |
+
if full_path.startswith("api"):
|
| 270 |
return {"detail": "Not Found"}
|
| 271 |
+
|
| 272 |
+
# 2. Check if the file exists (for assets like .js, .css, .png)
|
| 273 |
+
file_path = os.path.join(FRONTEND_PATH, full_path)
|
| 274 |
+
if os.path.isfile(file_path):
|
| 275 |
+
return FileResponse(file_path)
|
| 276 |
+
|
| 277 |
+
# 3. Fallback to index.html for React Router
|
| 278 |
index_file = os.path.join(FRONTEND_PATH, "index.html")
|
| 279 |
if os.path.exists(index_file):
|
| 280 |
return FileResponse(index_file)
|
| 281 |
+
|
| 282 |
return {"detail": "Frontend build not found"}
|
| 283 |
else:
|
| 284 |
@app.get("/")
|
| 285 |
def read_root():
|
| 286 |
return {"message": "Wafer Defect API is running. Frontend build folder not found."}
|
| 287 |
+
|
frontend/src/apiConfig.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
const API_BASE_URL =
|
| 2 |
|
| 3 |
export default API_BASE_URL;
|
|
|
|
| 1 |
+
const API_BASE_URL = '';
|
| 2 |
|
| 3 |
export default API_BASE_URL;
|