From 7cea119ad79541cdbc5dbbf3273e3cc9cbde02ca Mon Sep 17 00:00:00 2001 From: yiekheng Date: Sat, 2 May 2026 16:21:51 +0800 Subject: [PATCH] feat(web): make Werkzeug debug opt-in via CM_DEBUG --- app/cm_web_view.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/cm_web_view.py b/app/cm_web_view.py index 9020b78..509d7e5 100644 --- a/app/cm_web_view.py +++ b/app/cm_web_view.py @@ -13,6 +13,16 @@ PREFIX_PATTERN = os.getenv('CM_PREFIX_PATTERN', '') print("API: ", API_BASE_URL) print("Prefix pattern: ", PREFIX_PATTERN) + +def _debug_enabled() -> bool: + """Return True iff CM_DEBUG env var is set to a truthy value. + + Truthy: '1', 'true', 'yes' (case-insensitive, whitespace-trimmed). + Anything else, including unset, is False. Default-off so the + Werkzeug debugger is never reachable in production containers. + """ + return os.getenv("CM_DEBUG", "false").strip().lower() in ("1", "true", "yes") + # Beautiful HTML template with modern styling HTML_TEMPLATE = """ @@ -745,4 +755,4 @@ if __name__ == '__main__': print("Starting CM Web View...") print("Web interface will be available at: http://localhost:8000") print("Make sure the API server is running on port 3000") - app.run(host='0.0.0.0', port=8000, debug=True) + app.run(host='0.0.0.0', port=8000, debug=_debug_enabled())