From b52766ab1e0705b03d130467c76d278e2d1f6a7b Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 11 Nov 2018 16:06:06 +0200 Subject: [PATCH] Fix minor things in management API --- maubot/management/api/middleware.py | 1 - maubot/server.py | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/maubot/management/api/middleware.py b/maubot/management/api/middleware.py index 79bc26b..f58dcd8 100644 --- a/maubot/management/api/middleware.py +++ b/maubot/management/api/middleware.py @@ -39,7 +39,6 @@ async def error(request: web.Request, handler: Handler) -> web.Response: try: return await handler(request) except web.HTTPException as ex: - print(ex) if ex.status_code == 404: return resp.path_not_found elif ex.status_code == 405: diff --git a/maubot/server.py b/maubot/server.py index 06f1c4d..827fd7e 100644 --- a/maubot/server.py +++ b/maubot/server.py @@ -61,7 +61,7 @@ class MaubotServer: index_html = file.read() @web.middleware - async def frontend_404_middleware(request, handler): + async def frontend_404_middleware(request: web.Request, handler) -> web.Response: if hasattr(handler, "__self__") and isinstance(handler.__self__, web.StaticResource): try: return await handler(request) @@ -69,10 +69,13 @@ class MaubotServer: return web.Response(body=index_html, content_type="text/html") return await handler(request) + async def ui_base_redirect(_: web.Request) -> web.Response: + raise web.HTTPFound(f"{ui_base}/") + self.app.middlewares.append(frontend_404_middleware) self.app.router.add_get(f"{ui_base}/", lambda _: web.Response(body=index_html, content_type="text/html")) - self.app.router.add_get(ui_base, lambda _: web.HTTPFound(f"{ui_base}/")) + self.app.router.add_get(ui_base, ui_base_redirect) def setup_static_root_files(self, directory: str, ui_base: str) -> None: files = {