41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app import __version__
|
|
from app.config import Settings
|
|
from app.db import init_db
|
|
from app.room import RoomManager
|
|
from app.routes_admin import router as admin_router
|
|
from app.routes_student import router as student_router
|
|
|
|
|
|
def create_app(settings: Settings | None = None) -> FastAPI:
|
|
settings = settings or Settings.from_env()
|
|
rooms = RoomManager(settings)
|
|
app = FastAPI(title="Live In-Lecture Quiz Portal")
|
|
app.state.settings = settings
|
|
app.state.rooms = rooms
|
|
|
|
@app.on_event("startup")
|
|
async def startup() -> None:
|
|
await init_db(settings.db_path)
|
|
|
|
@app.get("/healthz")
|
|
async def healthz():
|
|
return {
|
|
"ok": True,
|
|
"version": __version__,
|
|
"sessions_active": await rooms.sessions_active(),
|
|
"ws_clients": rooms.ws_client_count(),
|
|
}
|
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
app.include_router(admin_router(settings, rooms))
|
|
app.include_router(student_router(settings, rooms))
|
|
return app
|
|
|
|
|
|
app = create_app()
|