Support clean home path, supplementing 'index.html' if needed
This commit is contained in:
@@ -50,7 +50,7 @@ select = [
|
|||||||
"__init__.py" = ["F401"]
|
"__init__.py" = ["F401"]
|
||||||
|
|
||||||
[tool.ruff.lint.mccabe]
|
[tool.ruff.lint.mccabe]
|
||||||
max-complexity = 10
|
max-complexity = 12
|
||||||
|
|
||||||
[tool.ruff.lint.pycodestyle]
|
[tool.ruff.lint.pycodestyle]
|
||||||
max-doc-length = 180
|
max-doc-length = 180
|
||||||
|
|||||||
@@ -58,8 +58,9 @@ def handle_error_code(http_code):
|
|||||||
return 'Unable to set up session', http_code
|
return 'Unable to set up session', http_code
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
@app.route('/<path:path>', methods=['GET', 'POST'])
|
@app.route('/<path:path>', methods=['GET', 'POST'])
|
||||||
def all_routes(path):
|
def all_routes(path = ''):
|
||||||
"""Intercept all routes and proxy it through a session.
|
"""Intercept all routes and proxy it through a session.
|
||||||
|
|
||||||
Loosely based on https://stackoverflow.com/a/20648053
|
Loosely based on https://stackoverflow.com/a/20648053
|
||||||
@@ -114,7 +115,7 @@ def all_routes(path):
|
|||||||
# Fallback to disallow
|
# Fallback to disallow
|
||||||
return handle_error_code(403)
|
return handle_error_code(403)
|
||||||
|
|
||||||
# check if the users exist or not
|
# Check if the users exist or not
|
||||||
if not session.get('id'):
|
if not session.get('id'):
|
||||||
# Our current URL, to which mothership will redirect back including a sessionstart
|
# Our current URL, to which mothership will redirect back including a sessionstart
|
||||||
original_url = f'{request.host_url}{path}'
|
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)
|
app.logger.info('Redirecting to mothership with %s', original_url)
|
||||||
return redirect(f'{app.config["MOTHERSHIP"]}/login?redirect={original_url}&callback={callback_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)
|
file_path = os.path.join(app.config['SERVE_DIR'], path)
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
app.logger.info('Serving file %s', str(file_path))
|
app.logger.info('Serving file %s', str(file_path))
|
||||||
@@ -131,8 +134,3 @@ def all_routes(path):
|
|||||||
else:
|
else:
|
||||||
app.logger.error('File not found: %s', str(file_path))
|
app.logger.error('File not found: %s', str(file_path))
|
||||||
return handle_error_code(404)
|
return handle_error_code(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
|
||||||
return redirect('/index.html')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user