URL Prefix middleware
This commit is contained in:
1 parent
8e5f91948f
commit
d8692ab20e
1 file changed
+16
@@ -3,6 +3,19 @@ from flask import Flask, g, session, send_from_directory
|
|||||||
from config import config
|
from config import config
|
||||||
from cmbnet.extensions import sock
|
from cmbnet.extensions import sock
|
||||||
|
|
||||||
|
class PrefixMiddleware:
|
||||||
|
def __init__(self, app, prefix=''):
|
||||||
|
self.app = app
|
||||||
|
self.prefix = prefix
|
||||||
|
|
||||||
|
def __call__(self, environ, start_response):
|
||||||
|
script_name = environ.get('HTTP_X_FORWARDED_PREFIX', '')
|
||||||
|
if script_name:
|
||||||
|
environ['SCRIPT_NAME'] = script_name
|
||||||
|
path_info = environ.get('PATH_INFO', '')
|
||||||
|
if path_info.startswith(script_name):
|
||||||
|
environ['PATH_INFO'] = path_info[len(script_name):]
|
||||||
|
return self.app(environ, start_response)
|
||||||
|
|
||||||
def create_app(config_name=None):
|
def create_app(config_name=None):
|
||||||
if config_name is None:
|
if config_name is None:
|
||||||
@@ -13,6 +26,9 @@ def create_app(config_name=None):
|
|||||||
static_folder='../static')
|
static_folder='../static')
|
||||||
app.config.from_object(config[config_name])
|
app.config.from_object(config[config_name])
|
||||||
|
|
||||||
|
# Middleware registrieren
|
||||||
|
app.wsgi_app = PrefixMiddleware(app.wsgi_app)
|
||||||
|
|
||||||
# Stelle sicher, dass instance Verzeichnis existiert
|
# Stelle sicher, dass instance Verzeichnis existiert
|
||||||
os.makedirs(app.instance_path, exist_ok=True)
|
os.makedirs(app.instance_path, exist_ok=True)
|
||||||
os.makedirs(app.config['LOG_DIR'], exist_ok=True)
|
os.makedirs(app.config['LOG_DIR'], exist_ok=True)
|
||||||
|
|||||||
Reference in new issue
Block a user