From b7a6199a171c649b1aecefb344a99c8b3c9d9d79 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Wed, 19 Mar 2025 14:06:28 +0100 Subject: [PATCH] Support clean home path, supplementing 'index.html' if needed --- pyproject.toml | 2 +- staticshield.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c5a4b13..96b8f33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ select = [ "__init__.py" = ["F401"] [tool.ruff.lint.mccabe] -max-complexity = 10 +max-complexity = 12 [tool.ruff.lint.pycodestyle] max-doc-length = 180 diff --git a/staticshield.py b/staticshield.py index 8981f17..938504d 100644 --- a/staticshield.py +++ b/staticshield.py @@ -58,8 +58,9 @@ def handle_error_code(http_code): return 'Unable to set up session', http_code +@app.route('/') @app.route('/', methods=['GET', 'POST']) -def all_routes(path): +def all_routes(path = ''): """Intercept all routes and proxy it through a session. Loosely based on https://stackoverflow.com/a/20648053 @@ -114,7 +115,7 @@ def all_routes(path): # Fallback to disallow return handle_error_code(403) - # check if the users exist or not + # Check if the users exist or not if not session.get('id'): # Our current URL, to which mothership will redirect back including a sessionstart original_url = f'{request.host_url}{path}' @@ -123,6 +124,8 @@ def all_routes(path): app.logger.info('Redirecting to mothership with %s', original_url) return redirect(f'{app.config["MOTHERSHIP"]}/login?redirect={original_url}&callback={callback_url}') + if path == '': + path = 'index.html' file_path = os.path.join(app.config['SERVE_DIR'], path) if os.path.isfile(file_path): app.logger.info('Serving file %s', str(file_path)) @@ -131,8 +134,3 @@ def all_routes(path): else: app.logger.error('File not found: %s', str(file_path)) return handle_error_code(404) - - -@app.route('/') -def index(): - return redirect('/index.html')