1
0
mirror of https://github.com/etesync/server synced 2024-11-29 12:08:07 +00:00

Support passing custom middlewares.

This commit is contained in:
Tom Hacohen 2020-12-29 10:12:36 +02:00
parent a8b97e60d4
commit f67730f42d

View File

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