import logging from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.config import settings from app.dependencies import _get_garage_sdk from app.routers import documents, search logger = logging.getLogger(__name__) app = FastAPI(title="DocHub API") app.add_middleware( CORSMiddleware, allow_origins=settings.cors_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(documents.router) app.include_router(search.router) @app.on_event("startup") def ensure_bucket_exists(): try: garage_sdk = _get_garage_sdk() existing_buckets = {b["Name"] for b in garage_sdk.list_buckets().get("Buckets", [])} if settings.garage_bucket not in existing_buckets: garage_sdk.create_bucket(Bucket=settings.garage_bucket) except Exception: logger.warning("Could not verify/create Garage bucket '%s' on startup", settings.garage_bucket, exc_info=True) @app.get("/health") def health(): return {"status": "ok"}