Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -253,9 +253,9 @@ async def get_metrics():
|
|
| 253 |
return metrics
|
| 254 |
|
| 255 |
# ---------------- Health probe (HF Spaces watchdog) -----------------
|
| 256 |
-
@app.get("/")
|
| 257 |
def health_check():
|
| 258 |
-
"""Health check
|
| 259 |
return {
|
| 260 |
"status": "ok",
|
| 261 |
"version": "2.0.0",
|
|
@@ -268,34 +268,59 @@ def health_check():
|
|
| 268 |
async def conversation_websocket(websocket: WebSocket, session_id: str):
|
| 269 |
await websocket_endpoint(websocket, session_id)
|
| 270 |
|
| 271 |
-
# ---------------- Serve
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
|
|
|
| 275 |
|
| 276 |
-
#
|
| 277 |
-
@app.get("/
|
| 278 |
-
async def
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
#
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
if index_path.exists():
|
| 291 |
-
return FileResponse(index_path)
|
| 292 |
|
| 293 |
-
return {"error": "Not found"}
|
| 294 |
-
|
| 295 |
-
# Mount static files for assets
|
| 296 |
-
app.mount("/", StaticFiles(directory=str(static_dir), html=True), name="static")
|
| 297 |
else:
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
if __name__ == "__main__":
|
| 301 |
log_info("🌐 Starting Flare backend on port 7860...")
|
|
|
|
| 253 |
return metrics
|
| 254 |
|
| 255 |
# ---------------- Health probe (HF Spaces watchdog) -----------------
|
| 256 |
+
@app.get("/api/health")
|
| 257 |
def health_check():
|
| 258 |
+
"""Health check endpoint - moved to /api/health"""
|
| 259 |
return {
|
| 260 |
"status": "ok",
|
| 261 |
"version": "2.0.0",
|
|
|
|
| 268 |
async def conversation_websocket(websocket: WebSocket, session_id: str):
|
| 269 |
await websocket_endpoint(websocket, session_id)
|
| 270 |
|
| 271 |
+
# ---------------- Serve static files ------------------------------------
|
| 272 |
+
# UI static files (production build)
|
| 273 |
+
static_path = Path(__file__).parent / "static"
|
| 274 |
+
if static_path.exists():
|
| 275 |
+
app.mount("/static", StaticFiles(directory=str(static_path)), name="static")
|
| 276 |
|
| 277 |
+
# Serve index.html for all non-API routes (SPA support)
|
| 278 |
+
@app.get("/", response_class=FileResponse)
|
| 279 |
+
async def serve_index():
|
| 280 |
+
"""Serve Angular app"""
|
| 281 |
+
index_path = static_path / "index.html"
|
| 282 |
+
if index_path.exists():
|
| 283 |
+
return FileResponse(str(index_path))
|
| 284 |
+
else:
|
| 285 |
+
return JSONResponse(
|
| 286 |
+
status_code=404,
|
| 287 |
+
content={"error": "UI not found. Please build the Angular app first."}
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# Catch-all route for SPA
|
| 291 |
+
@app.get("/{full_path:path}")
|
| 292 |
+
async def serve_spa(full_path: str):
|
| 293 |
+
"""Serve Angular app for all routes"""
|
| 294 |
+
# Skip API routes
|
| 295 |
+
if full_path.startswith("api/"):
|
| 296 |
+
return JSONResponse(status_code=404, content={"error": "Not found"})
|
| 297 |
|
| 298 |
+
# Serve static files
|
| 299 |
+
file_path = static_path / full_path
|
| 300 |
+
if file_path.exists() and file_path.is_file():
|
| 301 |
+
return FileResponse(str(file_path))
|
| 302 |
+
|
| 303 |
+
# Fallback to index.html for SPA routing
|
| 304 |
+
index_path = static_path / "index.html"
|
| 305 |
if index_path.exists():
|
| 306 |
+
return FileResponse(str(index_path))
|
| 307 |
|
| 308 |
+
return JSONResponse(status_code=404, content={"error": "Not found"})
|
|
|
|
|
|
|
|
|
|
| 309 |
else:
|
| 310 |
+
log_warning(f"⚠️ Static files directory not found at {static_path}")
|
| 311 |
+
log_warning(" Run 'npm run build' in flare-ui directory to build the UI")
|
| 312 |
+
|
| 313 |
+
@app.get("/")
|
| 314 |
+
async def no_ui():
|
| 315 |
+
"""No UI available"""
|
| 316 |
+
return JSONResponse(
|
| 317 |
+
status_code=503,
|
| 318 |
+
content={
|
| 319 |
+
"error": "UI not available",
|
| 320 |
+
"message": "Please build the Angular UI first. Run: cd flare-ui && npm run build",
|
| 321 |
+
"api_docs": "/docs"
|
| 322 |
+
}
|
| 323 |
+
)
|
| 324 |
|
| 325 |
if __name__ == "__main__":
|
| 326 |
log_info("🌐 Starting Flare backend on port 7860...")
|