From 1e4a5fc7918f732459b35004dba8cabfd03e5841 Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 8 Dec 2017 21:24:37 +0100 Subject: [PATCH] ROUTE_PREFIX for easier proxying --- larigira/config.py | 1 + larigira/dbadmin/__init__.py | 8 ++++++-- larigira/dbadmin/templates/edit_event.html | 2 +- larigira/rpc.py | 6 ++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/larigira/config.py b/larigira/config.py index 8927808..cdfd1f2 100644 --- a/larigira/config.py +++ b/larigira/config.py @@ -19,6 +19,7 @@ def get_conf(prefix='LARIGIRA_'): conf['CACHING_TIME'] = 10 conf['DB_URI'] = os.path.join(conf_dir, 'db.json') conf['SCRIPTS_PATH'] = os.path.join(conf_dir, 'scripts') + conf['ROUTE_PREFIX'] = '' conf['BOOTSTRAP_SERVE_LOCAL'] = True conf['SECRET_KEY'] = 'Please replace me!' conf['MPD_WAIT_START'] = True diff --git a/larigira/dbadmin/__init__.py b/larigira/dbadmin/__init__.py index 3113931..497c206 100644 --- a/larigira/dbadmin/__init__.py +++ b/larigira/dbadmin/__init__.py @@ -17,7 +17,9 @@ from larigira.timegen import get_timegenerator, timegenerate from larigira import forms from larigira.config import get_conf from .suggestions import get_suggestions -db = Blueprint('db', __name__, url_prefix='/db', template_folder='templates') +db = Blueprint('db', __name__, + url_prefix=get_conf()['ROUTE_PREFIX'] + '/db', + template_folder='templates') def get_model(): @@ -172,7 +174,9 @@ def edit_event(alarmid): actions = tuple(model.get_actions_by_alarm(alarm)) return render_template('edit_event.html', alarm=alarm, all_actions=allactions, - actions=actions) + actions=actions, + routeprefix=get_conf()['ROUTE_PREFIX'] + ) @db.route('/api/alarm//actions', methods=['POST']) diff --git a/larigira/dbadmin/templates/edit_event.html b/larigira/dbadmin/templates/edit_event.html index b928f07..e1ec13d 100644 --- a/larigira/dbadmin/templates/edit_event.html +++ b/larigira/dbadmin/templates/edit_event.html @@ -31,7 +31,7 @@ $(function() { return $(li).data('id'); }); jQuery.post( - '/db/api/alarm/' + my_id + '/actions', + '{{routeprefix}}/db/api/alarm/' + my_id + '/actions', {"actions[]": ids.toArray()} ); }); diff --git a/larigira/rpc.py b/larigira/rpc.py index 7ac7d5e..6d3daf2 100644 --- a/larigira/rpc.py +++ b/larigira/rpc.py @@ -11,8 +11,10 @@ from werkzeug.contrib.cache import SimpleCache from .dbadmin import db from .config import get_conf -rpc = Blueprint('rpc', __name__, url_prefix='/api') -viewui = Blueprint('view', __name__, url_prefix='/view', +rpc = Blueprint('rpc', __name__, + url_prefix=get_conf()['ROUTE_PREFIX'] + '/api') +viewui = Blueprint('view', __name__, + url_prefix=get_conf()['ROUTE_PREFIX'] + '/view', template_folder='templates')