40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.core.config import settings
|
|
from app.db.database import Base, engine
|
|
from app.models import models # noqa: F401 (register models)
|
|
from app.services.storage import ensure_bucket
|
|
from app.api.routes import health, collections, admin
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
Base.metadata.create_all(bind=engine)
|
|
try:
|
|
ensure_bucket()
|
|
except Exception as e:
|
|
# Don't crash the API if MinIO is briefly unavailable at startup.
|
|
print(f"[startup] MinIO bucket init skipped: {e}")
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
version=settings.VERSION,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.ALLOWED_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router, tags=["meta"])
|
|
app.include_router(collections.router, prefix="/collections", tags=["collections"])
|
|
app.include_router(admin.router, prefix="/admin", tags=["admin"])
|