hubmc-datagw/src/hubgw/main.py

34 lines
790 B
Python

"""FastAPI application factory."""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from hubgw.core.logging import setup_logging
from hubgw.context import AppContext
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application lifespan context."""
ctx = AppContext()
await ctx.startup()
yield
await ctx.shutdown()
def create_app() -> FastAPI:
"""Create and configure FastAPI application."""
app = FastAPI(
title="HubGW",
description="FastAPI Gateway for HubMC",
version="0.1.0",
lifespan=lifespan
)
# Setup logging
setup_logging()
# Include routers
from hubgw.api.v1.router import api_router
app.include_router(api_router, prefix="/api/v1")
return app