From 2b6d94c766775b8cf0ff4eeadb444e56fc94065d Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Thu, 24 Jul 2025 16:00:13 -0500 Subject: [PATCH 1/2] Refactor config to set DEBUG based on environment variable for better configuration management. Remove debug print statement from hooks to clean up response handling. --- inventory/app.py | 2 +- inventory/config.py | 2 +- inventory/routes/hooks.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/inventory/app.py b/inventory/app.py index 9b63deb..b39e7cb 100644 --- a/inventory/app.py +++ b/inventory/app.py @@ -3,4 +3,4 @@ from . import create_app app = create_app() if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + app.run() \ No newline at end of file diff --git a/inventory/config.py b/inventory/config.py index f0f7608..6d74fd6 100644 --- a/inventory/config.py +++ b/inventory/config.py @@ -9,7 +9,7 @@ def quote(value: str) -> str: class Config: SQLALCHEMY_TRACK_MODIFICATIONS = False - DEBUG = True + DEBUG = os.getenv('DEBUG', 'false').strip().lower() in ['true', '1', 'yes'] TESTING = False DB_BACKEND = os.getenv('DB_BACKEND', 'sqlite').lower() diff --git a/inventory/routes/hooks.py b/inventory/routes/hooks.py index 298a709..f5ecae2 100644 --- a/inventory/routes/hooks.py +++ b/inventory/routes/hooks.py @@ -6,7 +6,6 @@ from . import main @main.after_request def prettify_or_minify_html_response(response): - print(app.debug, response.content_type) if response.content_type.startswith("text/html"): try: html = response.get_data(as_text=True) From e5755066c3f2ea57e43e4044c9df28bfb008aacb Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Thu, 24 Jul 2025 16:02:26 -0500 Subject: [PATCH 2/2] Refactor prettify_or_minify_html_response to comment out minification logic for clarity and maintainability. --- inventory/routes/hooks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/inventory/routes/hooks.py b/inventory/routes/hooks.py index f5ecae2..d4e4f5c 100644 --- a/inventory/routes/hooks.py +++ b/inventory/routes/hooks.py @@ -14,13 +14,13 @@ def prettify_or_minify_html_response(response): if app.debug: pretty_html = soup.prettify() response.set_data(pretty_html.encode("utf-8")) # type: ignore - else: - # Minify by stripping extra whitespace between tags and inside text - minified_html = re.sub(r">\s+<", "><", str(soup)) # collapse whitespace between tags - minified_html = re.sub(r"\s{2,}", " ", minified_html) # collapse multi-spaces to one - minified_html = re.sub(r"\n+", "", minified_html) # remove newlines + #else: + # # Minify by stripping extra whitespace between tags and inside text + # minified_html = re.sub(r">\s+<", "><", str(soup)) # collapse whitespace between tags + # minified_html = re.sub(r"\s{2,}", " ", minified_html) # collapse multi-spaces to one + # minified_html = re.sub(r"\n+", "", minified_html) # remove newlines - response.set_data(minified_html.encode("utf-8")) # type: ignore + # response.set_data(minified_html.encode("utf-8")) # type: ignore response.headers['Content-Type'] = 'text/html; charset=utf-8' except Exception as e: