35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""FastAPI application factory."""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import Settings, get_settings
|
|
from app.core.exceptions import AppException, app_exception_handler
|
|
from app.core.logging import configure_logging
|
|
|
|
|
|
def create_app(settings: Settings | None = None) -> FastAPI:
|
|
resolved_settings = settings or get_settings()
|
|
configure_logging(resolved_settings.log_level)
|
|
|
|
application = FastAPI(
|
|
title=resolved_settings.app_name,
|
|
version=resolved_settings.app_version,
|
|
debug=resolved_settings.debug,
|
|
)
|
|
application.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=list(resolved_settings.cors_allow_origins),
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PATCH", "DELETE", "OPTIONS"],
|
|
allow_headers=["Authorization", "Content-Type", "Accept"],
|
|
)
|
|
application.add_exception_handler(AppException, app_exception_handler)
|
|
application.include_router(api_router)
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
|