diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-01-02 00:51:25 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-01-08 20:38:18 +0100 |
commit | 4578aa44fce996faf4711eb6e5fad25cdc86374c (patch) | |
tree | e776ac5d8d2d088625cfcb9d9cd0a3a06a98ed50 /mediabrowser | |
parent | 988f8cfc74446e7aa58f6e0ce916110e9ed23ca8 (diff) | |
download | flask-mediabrowser-4578aa44fce996faf4711eb6e5fad25cdc86374c.tar.gz flask-mediabrowser-4578aa44fce996faf4711eb6e5fad25cdc86374c.zip |
support reverse proxy
Diffstat (limited to 'mediabrowser')
-rw-r--r-- | mediabrowser/wsgi.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/mediabrowser/wsgi.py b/mediabrowser/wsgi.py index 7d80852..038ca5b 100644 --- a/mediabrowser/wsgi.py +++ b/mediabrowser/wsgi.py @@ -1,15 +1,36 @@ +import mediabrowser + from flask import Flask from werkzeug.contrib.cache import SimpleCache -import mediabrowser - import os +import logging - -"""Run via WSGI""" +logging.basicConfig(level=logging.INFO) root = os.getenv("MEDIABROWSER_ROOT") if not root: raise Exception('Must set MEDIABROWSER_ROOT variable') cache = SimpleCache() application = Flask("mediabrowser-demo") application.register_blueprint(mediabrowser.build(root, cache)) + +def reverse_proxified(app): + """ + Configure apache as: + RequestHeader set X-Script-Name /videos + """ + def wsgi_call(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 app(environ, start_response) + return wsgi_call + +application = reverse_proxified(application.wsgi_app) |