diff options
-rw-r--r-- | newspipe/bootstrap.py | 12 | ||||
-rw-r--r-- | newspipe/lib/utils.py | 9 |
2 files changed, 12 insertions, 9 deletions
diff --git a/newspipe/bootstrap.py b/newspipe/bootstrap.py index 9160c857..1af61d2f 100644 --- a/newspipe/bootstrap.py +++ b/newspipe/bootstrap.py @@ -5,6 +5,7 @@ import os from flask import Flask from flask import request +from flask import url_for as f_url_for from flask_babel import Babel from flask_babel import format_datetime from flask_migrate import Migrate @@ -111,3 +112,14 @@ application.jinja_env.filters["datetime"] = format_datetime application.jinja_env.filters["datetimeformat"] = datetimeformat # inject application in Jinja env application.jinja_env.globals["application"] = application + +@application.context_processor +def utility_processor(): + def url_for(endpoint, **values): + """ Custom reverse-proxy support for url_for """ + print(f"DEBUG: generating url_for {endpoint}") + _uf = f_url_for(endpoint, **values) + if application.config and "PREFIX" in application.config: + _uf = str(application.config("PREFIX")) + _uf + return _uf + return dict(url_for=url_for) diff --git a/newspipe/lib/utils.py b/newspipe/lib/utils.py index eb20ff4b..7e8e4a15 100644 --- a/newspipe/lib/utils.py +++ b/newspipe/lib/utils.py @@ -6,20 +6,11 @@ from hashlib import md5 import requests from flask import request -from flask import url_for as f_url_for from newspipe.bootstrap import application logger = logging.getLogger(__name__) -def url_for(endpoint, **values): - """ Custom reverse-proxy support for url_for """ - print(f"DEBUG: generating url_for {endpoint}") - _uf = f_url_for(endpoint, **values) - if application.config and "PREFIX" in application.config: - _uf = str(application.config("PREFIX")) + _uf - return _uf - def default_handler(obj, role="admin"): """JSON handler for default query formatting""" |