From 21b2522a652ce2ad4b5773ad0dc406ef0e5c7439 Mon Sep 17 00:00:00 2001 From: mb Date: Thu, 8 Dec 2022 19:52:09 +0100 Subject: [PATCH] adding application root back in loop again, as the HTML and PDF views break when using an URL prefix..... --- octomode.py | 18 ++++++++++++++++-- settings.py | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/octomode.py b/octomode.py index 70409cd..14f5fd3 100755 --- a/octomode.py +++ b/octomode.py @@ -128,12 +128,26 @@ def stylesheet(name): @APP.route('//html/') def html(name): - url = f"/{ name }/preview.html" + # only here we need application root to make all the URLs work..... + if APP.config['APPLICATION_ROOT'] == '/': + app_root = '' + elif APP.config['APPLICATION_ROOT'].endswith('/'): + app_root = APP.config['APPLICATION_ROOT'][:-1] + else: + app_root = APP.config['APPLICATION_ROOT'] + url = f"{ app_root }/{ name }/preview.html" return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) @APP.route('//pdf/') def pdf(name): - url = f"/{name}/pagedjs.html" + # only here we need application root to make all the URLs work..... + if APP.config['APPLICATION_ROOT'] == '/': + app_root = '' + elif APP.config['APPLICATION_ROOT'].endswith('/'): + app_root = APP.config['APPLICATION_ROOT'][:-1] + else: + app_root = APP.config['APPLICATION_ROOT'] + url = f"{ app_root }/{name}/pagedjs.html" return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) # ////////////////// diff --git a/settings.py b/settings.py index 9ba0f6c..96b6c1d 100644 --- a/settings.py +++ b/settings.py @@ -5,6 +5,7 @@ from dotenv import load_dotenv load_dotenv() # Bind them to Python variables +APPLICATION_ROOT = os.environ.get('OCTOMODE_APPLICATION_ROOT', '/') PORTNUMBER = int(os.environ.get('OCTOMODE_PORTNUMBER', 5001)) PAD_URL = os.environ.get('OCTOMODE_PAD_URL', 'https://pad.vvvvvvaria.org') PAD_API_URL = os.environ.get('OCTOMODE_PAD_API_URL', 'https://pad.vvvvvvaria.org/api/1.2.15')