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:
parent
a8b97e60d4
commit
f67730f42d
@ -13,7 +13,7 @@ from .invitation import invitation_incoming_router, invitation_outgoing_router
|
|||||||
from .msgpack import MsgpackResponse
|
from .msgpack import MsgpackResponse
|
||||||
|
|
||||||
|
|
||||||
def create_application(prefix=""):
|
def create_application(prefix="", middlewares=[]):
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="Etebase",
|
title="Etebase",
|
||||||
description="The Etebase server API documentation",
|
description="The Etebase server API documentation",
|
||||||
@ -51,6 +51,9 @@ def create_application(prefix=""):
|
|||||||
)
|
)
|
||||||
app.add_middleware(TrustedHostMiddleware, allowed_hosts=settings.ALLOWED_HOSTS)
|
app.add_middleware(TrustedHostMiddleware, allowed_hosts=settings.ALLOWED_HOSTS)
|
||||||
|
|
||||||
|
for middleware in middlewares:
|
||||||
|
app.add_middleware(middleware)
|
||||||
|
|
||||||
@app.exception_handler(CustomHttpException)
|
@app.exception_handler(CustomHttpException)
|
||||||
async def custom_exception_handler(request: Request, exc: CustomHttpException):
|
async def custom_exception_handler(request: Request, exc: CustomHttpException):
|
||||||
return MsgpackResponse(status_code=exc.status_code, content=exc.as_dict)
|
return MsgpackResponse(status_code=exc.status_code, content=exc.as_dict)
|
||||||
|
Loading…
Reference in New Issue
Block a user