from fastapi import FastAPI from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware from starlette.exceptions import HTTPException import app.utils.database from app.routers import document_router, loan_officer_router from app.utils.app_logger.exception_handlers import ( http_exception_handler, request_validation_exception_handler, unhandled_exception_handler, ) from app.utils.app_logger.middleware import log_request_middleware app = FastAPI() # allow cors origins = ["*"] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], expose_headers=["Content-Disposition"], ) # initialize logger app.middleware("http")(log_request_middleware) app.add_exception_handler(RequestValidationError, request_validation_exception_handler) app.add_exception_handler(HTTPException, http_exception_handler) app.add_exception_handler(Exception, unhandled_exception_handler) # initialize base routes @app.get("/") def base_route(): return {"msg": "Welcome to document service"} @app.get("/document/openapi.json", include_in_schema=False) def custom_swagger_ui_html(): return app.openapi() app.include_router(document_router.router, prefix="/file", tags=["File Upload"]) app.include_router(loan_officer_router.router, prefix="/loan_officer", tags=["Loan Officer Routes"])