31 lines
751 B
Python
31 lines
751 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api import api_router
|
|
from app.core.config import settings
|
|
from app.db.session import init_db
|
|
from app.services.scheduler import scheduler_service
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_db()
|
|
scheduler_service.start()
|
|
try:
|
|
yield
|
|
finally:
|
|
scheduler_service.shutdown()
|
|
|
|
|
|
app = FastAPI(title=settings.app_name, version="1.1.0", lifespan=lifespan)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.include_router(api_router, prefix=settings.api_prefix)
|