From f02ba6fdf5a9c1b87c8208b9251d51d791922df2 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Wed, 30 Aug 2023 15:24:17 -0400 Subject: add support for reverse-proxy in config --- instance/config.py | 2 ++ newspipe/bootstrap.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/instance/config.py b/instance/config.py index af5fe9b9..81f83f12 100644 --- a/instance/config.py +++ b/instance/config.py @@ -10,6 +10,8 @@ PORT = 5000 DEBUG = True API_ROOT = "/api/v2.0" +PREFIX = "/newspipe" + CSRF_ENABLED = True SECRET_KEY = "LCx3BchmHRxFzkEv4BqQJyeXRLXenf" SECURITY_PASSWORD_SALT = "L8gTsyrpRQEF8jNWQPyvRfv7U5kJkD" diff --git a/newspipe/bootstrap.py b/newspipe/bootstrap.py index 12044916..3905cd93 100644 --- a/newspipe/bootstrap.py +++ b/newspipe/bootstrap.py @@ -44,9 +44,20 @@ def set_logging( handler.setLevel(log_level) logger.setLevel(log_level) +class ReverseProxied(object): + def __init__(self, app, script_name): + self.app = app + self.script_name = script_name + + def __call__(self, environ, start_response): + environ['SCRIPT_NAME'] = self.script_name + return self.app(environ, start_response) + # Create Flask application application = Flask(__name__, instance_relative_config=True) +if "PREFIX" in application.config: + application.wsgi_app = ReverseProxied(application.wsgi_app, script_name=application.config["PREFIX"]) configuration = os.environ.get("NEWSPIPE_CONFIG", False) if configuration == "testing": application.debug = logging.DEBUG -- cgit