From 7c20c4ef19a5f3d6a9f5cf4780241d6d3ecee615 Mon Sep 17 00:00:00 2001 From: Kobe Mertens Date: Tue, 1 Oct 2024 15:33:58 +0200 Subject: [PATCH] Startup the flask dev server the correct way As indicated in the Flask documentation (https://flask.palletsprojects.com/en/2.3.x/server/#in-code) `app.run` is not the best way to run the flask dev server. It is better to run as `flask run`. This does not crash the server on errors, instead it logs and returns the error and stacktrace. --- start.sh | 2 +- web.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/start.sh b/start.sh index 46e4931..6868294 100644 --- a/start.sh +++ b/start.sh @@ -2,7 +2,7 @@ set -eu if [ ${MODE:-""} == "development" ]; then if [ -f /app/requirements.txt ]; then pip install -r /app/requirements.txt; fi - exec python web.py + exec flask --app web.py run --debug --port 80 --host "0.0.0.0" else exec gunicorn -k egg:meinheld#gunicorn_worker -c "$GUNICORN_CONF" "$APP_MODULE" fi diff --git a/web.py b/web.py index 905cb2c..faa9024 100644 --- a/web.py +++ b/web.py @@ -26,11 +26,8 @@ # Import the app from the service consuming the template app_file = os.environ.get('APP_ENTRYPOINT') -try: - module_path = 'ext.app.{}'.format(app_file) - import_module(module_path) -except Exception: - helpers.logger.exception('Exception raised when importing app code') +module_path = 'ext.app.{}'.format(app_file) +import_module(module_path) ####################### ## Start Application ##