- app/templates/: base layout with sidebar nav + 6 pages (dashboard, printers, jobs, filaments, todos, pricing) - app/routers/ui.py: HTML routes querying the DB live - API routes moved to /api/* prefix - requirements: jinja2, python-multipart Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from app.db import check_db, run_migrations
|
|
from app.routers import filaments, pricing, print_jobs, printers, todos
|
|
from app.routers import ui
|
|
|
|
logger = logging.getLogger("pops")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
ok, msg = check_db()
|
|
if ok:
|
|
logger.info("Database connection OK")
|
|
run_migrations()
|
|
else:
|
|
logger.warning("Database unreachable: %s", msg)
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="POPS", lifespan=lifespan)
|
|
|
|
# JSON API
|
|
app.include_router(printers.router, prefix="/api")
|
|
app.include_router(filaments.router, prefix="/api")
|
|
app.include_router(print_jobs.router, prefix="/api")
|
|
app.include_router(todos.router, prefix="/api")
|
|
app.include_router(pricing.router, prefix="/api")
|
|
|
|
# Web UI (must come after API to avoid route shadowing)
|
|
app.include_router(ui.router)
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
ok, msg = check_db()
|
|
return {
|
|
"status": "ok" if ok else "degraded",
|
|
"db": "connected" if ok else "unreachable",
|
|
"detail": msg,
|
|
}
|