- Default CORS_ORIGINS to http://localhost:5173 instead of "*" (still overridable) - Reject ".." and leading "/" in document keys/paths across get/save/delete/upload, mapped to HTTP 400 via new InvalidPathError - Add a delete button to DocumentEditor wired to deleteDocument + onDeleted, giving the existing DELETE API an actual UI entry point - Share a single lru_cache'd Meilisearch (and Minio) SDK client instance instead of constructing duplicates in dependencies.py - Add a startup check that creates the MinIO bucket if missing, tolerating MinIO being unreachable at boot without crashing the app
39 lines
945 B
Python
39 lines
945 B
Python
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import settings
|
|
from app.dependencies import _get_minio_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:
|
|
minio_sdk = _get_minio_sdk()
|
|
if not minio_sdk.bucket_exists(settings.minio_bucket):
|
|
minio_sdk.make_bucket(settings.minio_bucket)
|
|
except Exception:
|
|
logger.warning("Could not verify/create MinIO bucket '%s' on startup", settings.minio_bucket, exc_info=True)
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|