Structure changes to match other projects and minor logging improvements

This commit is contained in:
Ian Renton
2026-07-26 07:47:38 +01:00
parent ecab8d6d16
commit c3bcc1190d
483 changed files with 70 additions and 55 deletions
-16
View File
@@ -1,16 +0,0 @@
import logging
from tornado.web import StaticFileHandler, HTTPError
class QuietStaticFileHandler(StaticFileHandler):
"""Minor override of logging in StaticFileHandler to log HTTP errors at debug level instead of their usual
warning level. Without this, attacks on Spothole which try to do path traversal attacks would log exceptions
from inside Tornado, and the server logs would contain a lot of this type of content. This effectively changes
the log level of these exceptions to DEBUG so they are only logged if DEBUG level logging is enabled."""
def log_exception(self, typ, value, tb):
if isinstance(value, HTTPError):
logging.debug(value)
return
super().log_exception(typ, value, tb)
+6 -3
View File
@@ -18,7 +18,6 @@ from server.handlers.api.status import APIStatusHandler
from server.handlers.manifesthandler import ManifestHandler
from server.handlers.metrics import PrometheusMetricsHandler
from server.handlers.pagetemplate import PageTemplateHandler
from server.handlers.quietstaticfilehandler import QuietStaticFileHandler
_HERE = os.path.dirname(__file__ or "")
@@ -101,12 +100,16 @@ class WebServer:
if ALLOW_SPOTTING:
ui_routes += [(r"/add-spot", PageTemplateHandler, {"template_name": "add_spot", **handler_opts})]
# API docs, Prometheus metrics, webapp manifest and static assets are always available regardless of API-only mode.
# API docs, Prometheus metrics, webapp manifest and static assets are always available regardless of API-only
# mode.
misc_routes = [
(r"/apidocs", PageTemplateHandler, {"template_name": "apidocs", **handler_opts}),
(r"/metrics", PrometheusMetricsHandler),
(r"/manifest.webmanifest", ManifestHandler),
(r"/static/(.*)", QuietStaticFileHandler, {"path": os.path.join(_HERE, "../webassets")})
# If e.g. nginx is configured as a reverse proxy with a hard-coded path to static files, as per the README,
# this will never have to handle anything, but having it here allows Spothole to work without nginx for
# testing.
(r"/static/(.*)", StaticFileHandler, {"path": os.path.join(_HERE, "../static")})
]
app = tornado.web.Application(api_routes + ui_routes + misc_routes,