From 40651c327995aab2005c26ccd8b9c71fedb8f3ce Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 18 Nov 2020 01:55:02 +0100 Subject: [PATCH] [Script] Respect root if running devel server --- run_flaschengeist | 28 ++++++++++++++++++++++------ setup.py | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) 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