45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
"""FastAPI application factory and entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
|
|
from app.common.error_handler import register_exception_handlers
|
|
from app.core.config import settings
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan manager for startup/shutdown events."""
|
|
# Startup: initialize DB connections, cache, etc.
|
|
yield
|
|
# Shutdown: cleanup resources
|
|
|
|
|
|
def app_factory() -> FastAPI:
|
|
"""Create and configure FastAPI application instance.
|
|
|
|
Returns:
|
|
Configured FastAPI application.
|
|
"""
|
|
app = FastAPI(title=settings.app_name, debug=settings.debug, lifespan=lifespan)
|
|
|
|
# Register exception handlers
|
|
register_exception_handlers(app)
|
|
|
|
# Register routers (when added)
|
|
# from app.api.v1.router import api_router
|
|
# app.include_router(api_router, prefix="/api/v1")
|
|
|
|
return app
|
|
|
|
|
|
def main():
|
|
"""Run the application with uvicorn server."""
|
|
uvicorn.run(app_factory, factory=True, host=settings.host, port=settings.port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|