Spaces:
Sleeping
Sleeping
perf: startup menu preload + /ping keepalive endpoint
Browse files123456781 unmodified line1011121314151617181920212223112425262718 unmodified lines46474849505152535455565758"""Bell backend — voice ordering API for BYG Brewski (Bolna tool endpoints +frontend endpoints). Runs on HuggingFace Spaces (port 7860) or locally."""
from contextlib import asynccontextmanager
from fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware
1 unmodified linefrom routes import calls, copilot, menu, orders, reservations, tokens_route, webhooksfrom store import get_store
@asynccontextmanagerasync def lifespan(app: FastAPI): # Pre-warm the store on startup so the first tool call is fast. try: get_store().get_menu() except Exception: pass yield
app = FastAPI(title="Bell — BYG Brewski Voice Ordering API", version="1.0.0")app = FastAPI(title="Bell — BYG Brewski Voice Ordering API", version="1.0.0", lifespan=lifespan)
app.add_middleware( CORSMiddleware,18 unmodified lines return {"service": "bell-backend", "restaurant": "BYG Brewski", "docs": "/docs"}
@app.get("/ping")async def ping(): """Ultra-lightweight keepalive — frontend pings every 90s to prevent HF cold starts.""" return {"ok": True}
@app.get("/health")@app.get("/api/health")async def health(): """Read-only health check — never seeds or mutates state."""main.py+21-1