Support clean home path, supplementing 'index.html' if needed
This commit is contained in:
@@ -58,8 +58,9 @@ def handle_error_code(http_code):
|
||||
return 'Unable to set up session', http_code
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/<path:path>', 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')
|
||||
|
||||
Reference in New Issue
Block a user