Files
MAIA/backend/main.py
c-d-p 0c2bb5454b
All checks were successful
Build and Deploy Backend / Run Linters and Tests (push) Successful in 18s
Build and Deploy Backend / Build and Deploy (push) Successful in 1m10s
cors fix
2025-05-01 14:13:26 +02:00

38 lines
956 B
Python

from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
from typing import Any, Callable
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from core.database import get_engine, Base
from modules import router
import logging
logging.getLogger("passlib").setLevel(logging.ERROR) # fix bc package logging is broken
def lifespan_factory() -> Callable[[FastAPI], _AsyncGeneratorContextManager[Any]]:
@asynccontextmanager
async def lifespan(app: FastAPI):
# Base.metadata.drop_all(bind=get_engine())
Base.metadata.create_all(bind=get_engine())
yield
return lifespan
lifespan = lifespan_factory()
app = FastAPI(lifespan=lifespan)
app.include_router(router)
app.add_middleware(
CORSMiddleware,
allow_origins=["https://app.maia.depaoli.id.au"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/api/health")
def health():
return {"status": "ok"}