hubmc-datagw/src/hubgw/main.py

34 lines
790 B
Python
Raw Normal View History

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