"""Entry point for both roles. ROLE=hub (the default) serves the web UI and API; ROLE=probe runs a network probe. `update` imports this module as its pre-flight check.""" import contextlib import os from pathlib import Path if os.environ.get("ROLE", "hub").strip().lower() == "probe": from app.probe.server import app else: from app.hub.server import app DATA_DIR = Path(os.environ.get("DATA_DIR", "data")) _role_lifespan = app.router.lifespan_context @contextlib.asynccontextmanager async def lifespan(a): # Startup work goes here, not at import time: `update` imports this module as a check # before restarting. Shared by both roles; each role's own startup runs inside. DATA_DIR.mkdir(parents=True, exist_ok=True) async with _role_lifespan(a): yield app.router.lifespan_context = lifespan __all__ = ["app"]