diff --git a/mutalyzer/config/default_settings.py b/mutalyzer/config/default_settings.py index baab2823d38f144a61bcb6e526d87d09d3984d0f..8166f03d03a1311ec315a7ebd84e7dfc042c341b 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 1213b03467e16fa1919281538768813e0a317b22..a4fa196bfbdfdda21109f6da9f1d24fbce95069a 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