45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from contextlib import asynccontextmanager
|
|
from typing import AsyncIterator
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.controller.admin.login_controller import router as admin_login_router
|
|
from app.controller.admin.profile_controller import router as admin_profile_router
|
|
from app.controller.api.health_controller import router as api_health_router
|
|
from app.core.config import get_settings
|
|
from app.core.dependencies import bootstrap_database
|
|
from app.exception.handler import register_exception_handlers
|
|
from app.lib.response.admin_return import AdminReturn
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
await bootstrap_database()
|
|
yield
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
settings = get_settings()
|
|
application = FastAPI(title=settings.app_name, lifespan=lifespan)
|
|
application.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_allow_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
register_exception_handlers(application)
|
|
application.include_router(admin_login_router)
|
|
application.include_router(admin_profile_router)
|
|
application.include_router(api_health_router)
|
|
|
|
@application.get("/")
|
|
async def index() -> dict:
|
|
return AdminReturn().success("success", {"name": settings.app_name})
|
|
|
|
return application
|
|
|
|
|
|
app = create_app()
|