"""WS Gateway — stateless WebSocket proxy. Accepts Electron device connections, authenticates JWT (RS256 public key), and routes frames between Electron and downstream services via Redis pub/sub. This service has NO business logic — it only routes JSON frames. """ from contextlib import asynccontextmanager import logging from fastapi import FastAPI from shared.config import settings logging.basicConfig( level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s", ) @asynccontextmanager async def lifespan(app: FastAPI): yield from shared.redis import redis_client await redis_client.aclose() def create_app() -> FastAPI: app = FastAPI( title="Adiuva WS Gateway", version="0.1.0", docs_url="/docs" if settings.ENV == "dev" else None, redoc_url=None, lifespan=lifespan, ) from app.handler import router app.include_router(router, prefix="/api/v1") @app.get("/api/v1/health", tags=["health"]) async def health() -> dict: return {"status": "ok", "service": "ws-gateway", "version": app.version} return app app = create_app()