Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import socketio
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
@@ -8,6 +9,7 @@ from app.api import api_router
|
||||
from app.core.database import init_db
|
||||
from app.core.logging import get_logger, setup_logging
|
||||
from app.middleware.logging import LoggingMiddleware
|
||||
from app.services.socket import socket_manager
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -25,7 +27,7 @@ async def lifespan(_app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
logger.info("Shutting down application")
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
def create_app():
|
||||
"""Create and configure the FastAPI application."""
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
@@ -43,7 +45,8 @@ def create_app() -> FastAPI:
|
||||
# Include API routes
|
||||
app.include_router(api_router)
|
||||
|
||||
return app
|
||||
# Create Socket.IO app with fallback to FastAPI app
|
||||
return socketio.ASGIApp(socket_manager.sio, app)
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
||||
Reference in New Issue
Block a user