app: add support for debug endpoints

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-10-07 07:16:05 -04:00 committed by Eric Callahan
parent 86fc1057f7
commit 30e2ec04b7
2 changed files with 19 additions and 0 deletions

View File

@ -395,6 +395,24 @@ class MoonrakerApp:
params['location_prefix'] = location_prefix params['location_prefix'] = location_prefix
self.mutable_router.add_handler(pattern, FileUploadHandler, params) self.mutable_router.add_handler(pattern, FileUploadHandler, params)
def register_debug_handler(
self,
uri: str,
request_methods: List[str],
callback: APICallback,
transports: List[str] = ALL_TRANSPORTS,
wrap_result: bool = True
) -> None:
if not self.server.is_debug_enabled():
return
if not uri.startswith("/debug"):
raise self.server.error(
"Debug Endpoints must be registerd in the '/debug' path"
)
self.register_local_handler(
uri, request_methods, callback, transports, wrap_result
)
def remove_handler(self, endpoint: str) -> None: def remove_handler(self, endpoint: str) -> None:
api_def = self.api_cache.pop(endpoint, None) api_def = self.api_cache.pop(endpoint, None)
if api_def is not None: if api_def is not None:

View File

@ -88,6 +88,7 @@ class Server:
# Tornado Application/Server # Tornado Application/Server
self.moonraker_app = app = MoonrakerApp(config) self.moonraker_app = app = MoonrakerApp(config)
self.register_endpoint = app.register_local_handler self.register_endpoint = app.register_local_handler
self.register_debug_endpoint = app.register_debug_handler
self.register_static_file_handler = app.register_static_file_handler self.register_static_file_handler = app.register_static_file_handler
self.register_upload_handler = app.register_upload_handler self.register_upload_handler = app.register_upload_handler
self.register_api_transport = app.register_api_transport self.register_api_transport = app.register_api_transport