Rewrite server: FastAPI + auth (users/roles/tokens) + admin WebUI + server-authoritative covers/metadata
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""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}
|
||||
Reference in New Issue
Block a user