[Script] Respect root if running devel server

This commit is contained in:
Ferdinand Thiessen 2020-11-18 01:55:02 +01:00
parent 2d6b86e2eb
commit 40651c3279
2 changed files with 23 additions and 7 deletions

View File

@ -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,14 +120,10 @@ 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)

View File

@ -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