ciyidogan commited on
Commit
bfa2a8d
Β·
verified Β·
1 Parent(s): a4d1915

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -8,6 +8,7 @@ from pathlib import Path
8
  from utils import log
9
  from chat_handler import router as chat_router # ← start_session & chat
10
  from admin_routes import router as admin_router # ← Admin API endpoints
 
11
 
12
  app = FastAPI(
13
  title="Flare Orchestration Service",
@@ -15,20 +16,18 @@ app = FastAPI(
15
  description="LLM-driven intent & API flow engine (bootstrap)",
16
  )
17
 
18
- from spark_startup import run_in_thread
19
  run_in_thread()
20
 
21
- # ---------------- Health probe (HF Spaces watchdog) -----------------
22
- @app.get("/")
23
- def health_check():
24
- return {"status": "ok"}
25
-
26
  # ---------------- Core chat/session routes --------------------------
27
  app.include_router(chat_router)
28
 
29
  # ---------------- Admin API routes ----------------------------------
30
  app.include_router(admin_router)
31
 
 
 
 
 
32
 
33
  # ---------------- Serve Angular UI if exists ------------------------
34
  static_path = Path("static")
@@ -38,11 +37,19 @@ if static_path.exists() and static_path.is_dir():
38
  if assets_path.exists() and assets_path.is_dir():
39
  app.mount("/assets", StaticFiles(directory=str(assets_path)), name="assets")
40
 
 
 
 
 
 
 
 
 
41
  # Catch-all route for Angular routing (must be last!)
42
  @app.get("/{full_path:path}")
43
  async def serve_angular(full_path: str):
44
  # Don't catch API routes
45
- if full_path.startswith("api/") or full_path in ["start_session", "chat"]:
46
  return {"error": "Not found"}, 404
47
 
48
  # Return Angular index.html for all other routes
@@ -50,6 +57,11 @@ if static_path.exists() and static_path.is_dir():
50
  if index_path.exists():
51
  return FileResponse(str(index_path))
52
  return {"error": "UI not found"}, 404
 
 
 
 
 
53
 
54
  if __name__ == "__main__":
55
  log("🌐 Starting Flare backend …")
 
8
  from utils import log
9
  from chat_handler import router as chat_router # ← start_session & chat
10
  from admin_routes import router as admin_router # ← Admin API endpoints
11
+ from spark_startup import run_in_thread
12
 
13
  app = FastAPI(
14
  title="Flare Orchestration Service",
 
16
  description="LLM-driven intent & API flow engine (bootstrap)",
17
  )
18
 
 
19
  run_in_thread()
20
 
 
 
 
 
 
21
  # ---------------- Core chat/session routes --------------------------
22
  app.include_router(chat_router)
23
 
24
  # ---------------- Admin API routes ----------------------------------
25
  app.include_router(admin_router)
26
 
27
+ # ---------------- Health probe (HF Spaces watchdog) -----------------
28
+ @app.get("/")
29
+ def health_check():
30
+ return {"status": "ok"}
31
 
32
  # ---------------- Serve Angular UI if exists ------------------------
33
  static_path = Path("static")
 
37
  if assets_path.exists() and assets_path.is_dir():
38
  app.mount("/assets", StaticFiles(directory=str(assets_path)), name="assets")
39
 
40
+ # Root path - serve index.html
41
+ @app.get("/")
42
+ async def serve_root():
43
+ index_path = static_path / "index.html"
44
+ if index_path.exists():
45
+ return FileResponse(str(index_path))
46
+ return {"status": "ok"} # Fallback to health check
47
+
48
  # Catch-all route for Angular routing (must be last!)
49
  @app.get("/{full_path:path}")
50
  async def serve_angular(full_path: str):
51
  # Don't catch API routes
52
+ if full_path.startswith("api/") or full_path in ["start_session", "chat", "health"]:
53
  return {"error": "Not found"}, 404
54
 
55
  # Return Angular index.html for all other routes
 
57
  if index_path.exists():
58
  return FileResponse(str(index_path))
59
  return {"error": "UI not found"}, 404
60
+ else:
61
+ # No UI built, just health endpoint
62
+ @app.get("/")
63
+ def health_check():
64
+ return {"status": "ok", "message": "UI not found. Build Angular app first."}
65
 
66
  if __name__ == "__main__":
67
  log("🌐 Starting Flare backend …")