From c30037dead4d30b3773d0eeffc1eb8a173281a94 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 25 Jun 2014 17:15:00 +0200
Subject: [PATCH] Add REVERSE_PROXIED configuration setting

---
 mutalyzer/config/default_settings.py |  6 ++++++
 mutalyzer/website/__init__.py        | 16 ++++------------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/mutalyzer/config/default_settings.py b/mutalyzer/config/default_settings.py
index baab2823..8166f03d 100644
--- a/mutalyzer/config/default_settings.py
+++ b/mutalyzer/config/default_settings.py
@@ -25,6 +25,12 @@ MAX_CACHE_SIZE = 50 * 1048576 # 50 MB
 # Maximum size for uploaded and downloaded files (in bytes).
 MAX_FILE_SIZE = 10 * 1048576 # 10 MB
 
+# The WSGI application runs behind a reverse proxy (e.g., nginx using
+# proxy_pass). This needs to be set if the application is mapped to a URL
+# other than / or a different HTTP scheme is used by the reverse proxy.
+# http://flask.pocoo.org/snippets/35/
+REVERSE_PROXIED = False
+
 # Redis connection URI (can be any redis-py connection URI). Set to `None` to
 # silently use a mock Redis. Redis is only used for non-essential features.
 REDIS_URI = None
diff --git a/mutalyzer/website/__init__.py b/mutalyzer/website/__init__.py
index 1213b034..a4fa196b 100644
--- a/mutalyzer/website/__init__.py
+++ b/mutalyzer/website/__init__.py
@@ -14,7 +14,7 @@ from mutalyzer.db import session
 
 
 # Todo: Perhaps we also need this for the RPC services?
-class ReverseProxied(object):
+class _ReverseProxied(object):
     """
     Wrap the application in this middleware and configure the front-end server
     to add these headers, to let you quietly bind this to a URL other than /
@@ -62,6 +62,9 @@ def create_app():
                 template_folder=os.path.abspath(template_folder),
                 static_folder=os.path.abspath(static_folder))
 
+    if settings.REVERSE_PROXIED:
+        app.wsgi_app = _ReverseProxied(app.wsgi_app)
+
     app.config.update(DEBUG=settings.DEBUG,
                       TESTING=settings.TESTING,
                       MAX_CONTENT_LENGTH=settings.MAX_FILE_SIZE)
@@ -80,14 +83,3 @@ def create_app():
         session.remove()
 
     return app
-
-
-def create_reverse_proxied_app():
-    """
-    Create a Flask instance for Mutalyzer running behind a reverse proxy.
-
-    See :func:`create_app` and :class:`ReverseProxied`.
-    """
-    app = create_app()
-    app.wsgi_app = ReverseProxied(app.wsgi_app)
-    return app
-- 
GitLab