From 5dcfcb97236f5240670e0d1f7d4d62b5c63a8be8 Mon Sep 17 00:00:00 2001 From: c-bata Date: Tue, 22 Mar 2022 14:10:20 +0900 Subject: [PATCH] Disable gzip when DEBUG mode is enabled --- DEVELOPMENT.md | 4 ++-- optuna_dashboard/_app.py | 4 ++-- optuna_dashboard/_cli.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 955a1354..187412f8 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -54,10 +54,10 @@ $ optuna-dashboard sqlite:///db.sqlite3 Environment variables for development -If you set `OPTUNA_DASHBOARD_AUTO_RELOAD=1`, the server will automatically restart when the source codes are changed. +If you set `OPTUNA_DASHBOARD_DEBUG=1`, the server will automatically restart when the source codes are changed. ``` -$ OPTUNA_DASHBOARD_AUTO_RELOAD=1 optuna-dashboard sqlite:///db.sqlite3 +$ OPTUNA_DASHBOARD_DEBUG=1 optuna-dashboard sqlite:///db.sqlite3 ``` diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index 214648e8..167a6ed6 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -102,7 +102,7 @@ def get_trials( return trials -def create_app(storage: BaseStorage) -> Bottle: +def create_app(storage: BaseStorage, debug: bool = False) -> Bottle: app = Bottle() @app.hook("before_request") @@ -256,7 +256,7 @@ def create_app(storage: BaseStorage) -> Bottle: @app.get("/static/") def send_static(filename: str) -> BottleViewReturn: - if "gzip" in request.headers["Accept-Encoding"]: + if not debug and "gzip" in request.headers["Accept-Encoding"]: gz_filename = filename.strip("/\\") + ".gz" if os.path.exists(os.path.join(STATIC_DIR, gz_filename)): filename = gz_filename diff --git a/optuna_dashboard/_cli.py b/optuna_dashboard/_cli.py index c97ca482..15df49be 100644 --- a/optuna_dashboard/_cli.py +++ b/optuna_dashboard/_cli.py @@ -11,7 +11,7 @@ from . import __version__ from ._app import create_app -AUTO_RELOAD = os.environ.get("OPTUNA_DASHBOARD_AUTO_RELOAD") == "1" +DEBUG = os.environ.get("OPTUNA_DASHBOARD_DEBUG") == "1" SERVER_CHOICES = ["wsgiref", "gunicorn"] @@ -22,7 +22,7 @@ def run_wsgiref(app: Bottle, host: str, port: int, quiet: bool) -> None: port=port, server="wsgiref", quiet=quiet, - reloader=AUTO_RELOAD, + reloader=DEBUG, ) @@ -68,7 +68,7 @@ def main() -> None: else: storage = RDBStorage(args.storage) - app = create_app(storage) + app = create_app(storage, debug=DEBUG) if args.server == "wsgiref": run_wsgiref(app, args.host, args.port, args.quiet) elif args.server == "gunicorn":