EricaLuvGemma commited on
Commit
2eb637d
Β·
verified Β·
1 Parent(s): abd893d

Update backend/main.py

Browse files
Files changed (1) hide show
  1. backend/main.py +21 -7
backend/main.py CHANGED
@@ -380,15 +380,29 @@ async def docker_images():
380
  return {"images": images}
381
 
382
 
383
- # ── Health ────────────────────────────────────────────────────────────────────
384
 
385
- @app.get("/")
386
- async def health():
387
  return {"status": "ok", "name": "TreyOS", "version": "1.0.0"}
388
 
389
 
390
- # ── Serve Frontend ────────────────────────────────────────────────────────────
391
 
392
- frontend_path = Path(__file__).parent.parent / "frontend" / "dist"
393
- if frontend_path.exists():
394
- app.mount("/app", StaticFiles(directory=str(frontend_path), html=True), name="frontend")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  return {"images": images}
381
 
382
 
383
+ # ── Health Check (Moved to avoid colliding with Root UI) ──────────────────────
384
 
385
+ @app.get("/health")
386
+ async def health_check():
387
  return {"status": "ok", "name": "TreyOS", "version": "1.0.0"}
388
 
389
 
390
+ # ── Serve Frontend UI ─────────────────────────────────────────────────────────
391
 
392
+ from fastapi.responses import HTMLResponse
393
+
394
+ @app.get("/", response_class=HTMLResponse)
395
+ async def serve_root_ui():
396
+ """Serves the main structural HTML interface directly at the app root."""
397
+ # Looks for TreyOS-connected.html in the root workspace directory (/trey)
398
+ root_html_path = Path(__file__).parent.parent / "TreyOS-connected.html"
399
+ if root_html_path.exists():
400
+ return root_html_path.read_text(encoding="utf-8")
401
+ else:
402
+ raise HTTPException(status_code=404, detail="TreyOS-connected.html not found in root context.")
403
+
404
+
405
+ # Correctly mount the real frontend directory containing treyos-client.js
406
+ real_frontend_path = Path(__file__).parent.parent / "frontend"
407
+ if real_frontend_path.exists():
408
+ app.mount("/frontend", StaticFiles(directory=str(real_frontend_path)), name="frontend")