d36aeb8636
Co-authored-by: multica-agent <github@multica.ai>
51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .api.router import api_router
|
|
from .core.config import get_settings
|
|
from .core.database import SessionLocal, init_db
|
|
from .services.scheduled_task_service import seed_default_scheduled_tasks
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_: FastAPI):
|
|
init_db()
|
|
db = SessionLocal()
|
|
try:
|
|
seed_default_scheduled_tasks(db)
|
|
db.commit()
|
|
finally:
|
|
db.close()
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.api_name,
|
|
version=settings.api_version,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_origin_regex=settings.cors_origin_regex,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/health")
|
|
def health() -> dict[str, str]:
|
|
return {
|
|
"status": "ok",
|
|
"service": settings.api_name,
|
|
"version": settings.api_version,
|
|
}
|
|
|
|
app.include_router(api_router)
|