57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
"""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.
|
|
"""
|
|
|
|
import sys
|
|
from contextlib import asynccontextmanager
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
# Ensure the repo root is on sys.path so "shared" is importable in local dev.
|
|
_repo_root = str(Path(__file__).resolve().parents[3])
|
|
if _repo_root not in sys.path:
|
|
sys.path.insert(0, _repo_root)
|
|
|
|
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()
|