40 lines
943 B
Python
40 lines
943 B
Python
"""psppt server: FastAPI app assembly."""
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.db import init_db
|
|
|
|
from . import api, config, web
|
|
from .security import ensure_admin
|
|
|
|
log = logging.getLogger("psppt.server")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI):
|
|
init_db()
|
|
created = ensure_admin(config.ADMIN_USERNAME, config.ADMIN_PASSWORD)
|
|
if created:
|
|
log.warning(
|
|
"Created initial admin user %r with the configured password — change it now.",
|
|
config.ADMIN_USERNAME,
|
|
)
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="psppt server", lifespan=lifespan)
|
|
|
|
app.include_router(api.router)
|
|
app.include_router(web.router)
|
|
|
|
app.mount("/static", StaticFiles(directory=str(Path(__file__).parent / "static")), name="static")
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"ok": True}
|