From f67730f42d2a78acadf28db253bf76c0f3630ba2 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 29 Dec 2020 10:12:36 +0200 Subject: [PATCH] Support passing custom middlewares. --- etebase_fastapi/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/etebase_fastapi/main.py b/etebase_fastapi/main.py index 69303bf..534798e 100644 --- a/etebase_fastapi/main.py +++ b/etebase_fastapi/main.py @@ -13,7 +13,7 @@ from .invitation import invitation_incoming_router, invitation_outgoing_router from .msgpack import MsgpackResponse -def create_application(prefix=""): +def create_application(prefix="", middlewares=[]): app = FastAPI( title="Etebase", description="The Etebase server API documentation", @@ -51,6 +51,9 @@ def create_application(prefix=""): ) app.add_middleware(TrustedHostMiddleware, allowed_hosts=settings.ALLOWED_HOSTS) + for middleware in middlewares: + app.add_middleware(middleware) + @app.exception_handler(CustomHttpException) async def custom_exception_handler(request: Request, exc: CustomHttpException): return MsgpackResponse(status_code=exc.status_code, content=exc.as_dict)