Support passing custom middlewares.

master
Tom Hacohen 4 years ago
parent a8b97e60d4
commit f67730f42d

@ -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)

Loading…
Cancel
Save