Fix minor things in management API
This commit is contained in:
parent
fd5672b3dd
commit
b52766ab1e
@ -39,7 +39,6 @@ async def error(request: web.Request, handler: Handler) -> web.Response:
|
|||||||
try:
|
try:
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
except web.HTTPException as ex:
|
except web.HTTPException as ex:
|
||||||
print(ex)
|
|
||||||
if ex.status_code == 404:
|
if ex.status_code == 404:
|
||||||
return resp.path_not_found
|
return resp.path_not_found
|
||||||
elif ex.status_code == 405:
|
elif ex.status_code == 405:
|
||||||
|
@ -61,7 +61,7 @@ class MaubotServer:
|
|||||||
index_html = file.read()
|
index_html = file.read()
|
||||||
|
|
||||||
@web.middleware
|
@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):
|
if hasattr(handler, "__self__") and isinstance(handler.__self__, web.StaticResource):
|
||||||
try:
|
try:
|
||||||
return await handler(request)
|
return await handler(request)
|
||||||
@ -69,10 +69,13 @@ class MaubotServer:
|
|||||||
return web.Response(body=index_html, content_type="text/html")
|
return web.Response(body=index_html, content_type="text/html")
|
||||||
return await handler(request)
|
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.middlewares.append(frontend_404_middleware)
|
||||||
self.app.router.add_get(f"{ui_base}/", lambda _: web.Response(body=index_html,
|
self.app.router.add_get(f"{ui_base}/", lambda _: web.Response(body=index_html,
|
||||||
content_type="text/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:
|
def setup_static_root_files(self, directory: str, ui_base: str) -> None:
|
||||||
files = {
|
files = {
|
||||||
|
Loading…
Reference in New Issue
Block a user