from __future__ import annotations from contextlib import asynccontextmanager from fastapi import FastAPI, APIRouter from fastapi.middleware.cors import CORSMiddleware from src.apis import chat, health from src.config import get_settings from src.session import Base, engine from src.services.blog import load_runtime_blog_index, blog_library_sync_service settings = get_settings() api_router = APIRouter() api_router.include_router(health.router) api_router.include_router(chat.router, prefix=settings.api_prefix) @asynccontextmanager async def lifespan(app: FastAPI): Base.metadata.create_all(bind=engine) blog_library_sync_service.sync() load_runtime_blog_index() yield def create_app() -> FastAPI: app = FastAPI(title=settings.app_name, lifespan=lifespan) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=False, allow_methods=["*"], allow_headers=["*"], ) app.include_router(api_router) return app