Newer
Older
This is an Application Server Gateway Interface (ASGI) application
and can be run using uvicorn, or any other ASGI server:
import logging
import os
Hobbs, Alexandra (Contractor)
committed
from contextlib import asynccontextmanager
from fastapi import FastAPI
from starlette.responses import RedirectResponse
from .db import database
LOG_BASIC_CONFIG = os.getenv("LOG_BASIC_CONFIG", "false")
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
if LOG_BASIC_CONFIG == "true":
logging.basicConfig(level=LOG_LEVEL)
Hobbs, Alexandra (Contractor)
committed
@asynccontextmanager
async def lifespan(app: FastAPI):
# on startup
await database.connect()
Hobbs, Alexandra (Contractor)
committed
yield
# on shutdown
await database.disconnect()
Hobbs, Alexandra (Contractor)
committed
app = FastAPI(lifespan=lifespan)
app.mount("/ws/secure", secure.app)
app.mount("/ws", ws.app)
@app.get("/", include_in_schema=False)
async def redirect_to_ws():
return RedirectResponse("/ws")