diff --git a/run_flaschengeist b/run_flaschengeist index 23f338a..3cf034f 100644 --- a/run_flaschengeist +++ b/run_flaschengeist @@ -4,6 +4,26 @@ import argparse import sys import pkg_resources +from werkzeug.middleware.dispatcher import DispatcherMiddleware + +from flaschengeist.config import config + + +class PrefixMiddleware(object): + + def __init__(self, app, prefix=''): + self.app = app + self.prefix = prefix + + def __call__(self, environ, start_response): + + if environ['PATH_INFO'].startswith(self.prefix): + environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):] + environ['SCRIPT_NAME'] = self.prefix + return self.app(environ, start_response) + else: + start_response('404', [('Content-Type', 'text/plain')]) + return ["This url does not belong to the app.".encode()] class InterfaceGenerator: @@ -100,15 +120,11 @@ def run(arguments): app = create_app() with app.app_context(): + app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=config["FLASCHENGEIST"].get("root", "")) if arguments.debug: app.run(arguments.host, arguments.port, debug=True) else: - try: - import bjoern - - bjoern.run(app, arguments.host, arguments.port, reuse_port=True) - except ImportError: - app.run(arguments.host, arguments.port, debug=False) + app.run(arguments.host, arguments.port, debug=False) def export(arguments): diff --git a/setup.py b/setup.py index 527dca7..d97177b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( # Needed for python < 3.7 "backports-datetime-fromisoformat", ], - extras_require={"ldap": ["flask_ldapconn", "ldap3"], "bjoern": ["bjoern"]}, + extras_require={"ldap": ["flask_ldapconn", "ldap3"]}, entry_points={ "flaschengeist.plugin": [ # Authentication providers