From 94d99862bd613520c6be17d3a58cc9e2a3cc041e Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 27 May 2020 12:52:41 +0200 Subject: [PATCH] Use werkzeugs pre implemented ProxyFix middleware --- app/__init__.py | 12 ------------ config.py | 9 ++++++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 5e8a0d29..3a1f54fc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,17 +7,6 @@ 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() @@ -28,7 +17,6 @@ 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) diff --git a/config.py b/config.py index 54224ebd..5b46863a 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ +from werkzeug.middleware.proxy_fix import ProxyFix import os import logging @@ -33,7 +34,13 @@ class Config: @staticmethod def init_app(app): - pass + proxy_fix_kwargs = { + 'x_for': 1, + 'x_host': 1, + 'x_port': 1, + 'x_proto': 1, + } + app.wsgi_app = ProxyFix(app.wsgi_app, **proxy_fix_kwargs) class DevelopmentConfig(Config):