From 814821a2bdc4f274b7318ca2f0556da4c7b4e4c6 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch <pjentsch@sfb1288inf-Laptop.fritz.box> Date: Wed, 27 May 2020 11:36:28 +0200 Subject: [PATCH] Make flask respect https! :D See: https://stackoverflow.com/questions/14810795/flask-url-for-generating-http-url-instead-of-https/37842465#37842465 --- app/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 3a1f54fc..5e8a0d29 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,6 +7,17 @@ from flask_sqlalchemy import SQLAlchemy import logging +class CustomProxyFix(object): + def __init__(self, app): + self.app = app + + def __call__(self, environ, start_response): + scheme = environ.get('HTTP_X_FORWARDED_PROTO') + if scheme: + environ['wsgi.url_scheme'] = scheme + return self.app(environ, start_response) + + db = SQLAlchemy() logger = logging.getLogger(__name__) login_manager = LoginManager() @@ -17,6 +28,7 @@ socketio = SocketIO() def create_app(config_name): app = Flask(__name__) + app.wsgi_app = CustomProxyFix(app.wsgi_app) app.config.from_object(config[config_name]) config[config_name].init_app(app) -- GitLab