"""FastAPI application entry point. Run locally with:: uvicorn app.main:app --reload --port 8000 """ from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from app.api.router import api_router from app.core.config import get_settings from app.crud.reference import UnknownReference settings = get_settings() app = FastAPI( title=settings.app_name, debug=settings.debug, ) 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) @app.exception_handler(UnknownReference) async def unknown_reference_handler( request: Request, error: UnknownReference ) -> JSONResponse: """Answer a citation to literature that is not in the library. The refusal is raised deep in the data layer, where the ids are known, and turned into the API's own vocabulary here rather than at every route that might write a citation. The body matches what the rest of the API returns for a rejected request, so a client needs no special case. """ return JSONResponse(status_code=400, content={"detail": str(error)})