Commit d580e08f authored by Pietro Albini's avatar Pietro Albini

Hopefully fix wrong urls with managetests

parent 1e6cc20c
......@@ -38,7 +38,7 @@ def cli():
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def run(cache, gunicorn_config, port, public, workers, debug):
# Create the application instance
app = uitwww.create_app(cache)
app = utils.ReverseProxied(uitwww.create_app(cache))
host = ""
if public:
......@@ -49,3 +49,39 @@ class GunicornInstance(baseapp.BaseApplication):
if is None:
raise RuntimeError("Application object not set")
class ReverseProxied:
'''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 / and to an HTTP scheme that is
different than what is used locally.
Created by Peter Hansen and released in the public domain.
In nginx:
location /myprefix {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /myprefix;
:param app: the WSGI application
def __init__(self, app): = app
def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
scheme = environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme
return, start_response)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment