Fix static handler 404 error

This commit is contained in:
luukas 2021-04-17 18:12:23 +03:00
parent 47305d74d9
commit 2e2d338c9d
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,15 @@
import tornado.web
from typing import (
Optional
)
from app.classes.shared.console import console
class CustomStaticHandler(tornado.web.StaticFileHandler):
def validate_absolute_path(self, root: str, absolute_path: str) -> Optional[str]:
try:
return super().validate_absolute_path(root, absolute_path)
except tornado.web.HTTPError as error:
if 'HTTP 404: Not Found' in str(error):
self.set_status(404)
self.finish({'error':'NOT_FOUND', 'info':'The requested resource was not found on the server'})

View File

@ -25,6 +25,7 @@ try:
from app.classes.web.ajax_handler import AjaxHandler
from app.classes.web.api_handler import ServersStats, NodeStats
from app.classes.web.websocket_handler import SocketHandler
from app.classes.web.static_handler import CustomStaticHandler
from app.classes.shared.translation import translation
except ModuleNotFoundError as e:
@ -143,7 +144,9 @@ class Webserver:
autoreload=False,
log_function=self.log_function,
login_url="/login",
default_handler_class=PublicHandler
default_handler_class=PublicHandler,
static_handler_class=CustomStaticHandler,
serve_traceback=debug_errors,
)
self.HTTP_Server = tornado.httpserver.HTTPServer(app)