39 lines
894 B
Python
39 lines
894 B
Python
"""CalCount FastAPI app entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from database import run_migrations
|
|
from routers import foods, log, meals, off, targets
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Migrations from day one, applied at startup (spec §8.1 rule 9)
|
|
run_migrations()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="CalCount", lifespan=lifespan)
|
|
|
|
# Vite dev server origin; tighten for production deployment
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:5173"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(foods.router)
|
|
app.include_router(log.router)
|
|
app.include_router(targets.router)
|
|
app.include_router(off.router)
|
|
app.include_router(meals.router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
def health():
|
|
return {"status": "ok"}
|