Skip to content

Commit

Permalink
Allow specifying a curstom tenant_path_prefix as env
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jul 3, 2024
1 parent 3165ac9 commit f42d553
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions qwc_services_core/tenant_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, app, _header=None, _ignore_default=None):
self.app = app
self.tenant_handler = TenantHandlerBase()
self.service_prefix = os.environ.get(
'QWC_SERVICE_PREFIX', '/').rstrip('/') + '/'
'QWC_SERVICE_PREFIX', '/').rstrip('/')

def __call__(self, environ, start_response):
# environ in request http://localhost:9090/base/pages/test.html?arg=1
Expand All @@ -182,7 +182,7 @@ def __call__(self, environ, start_response):
):
# add tenant path prefix for multitenancy
# NOTE: skipped if tenant already in path when using TENANT_URL_RE
prefix = self.service_prefix + tenant
prefix = os.environ.get('TENANT_PATH_PREFIX', '@service_prefix@/@tenant@').replace('@service_prefix@', self.service_prefix).replace('@tenant@', tenant)
environ['SCRIPT_NAME'] = prefix + environ.get(
'SCRIPT_NAME', '')
return self.app(environ, start_response)
Expand All @@ -200,9 +200,9 @@ def __init__(self, environ):
def tenant_path_prefix(self):
"""Tenant path prefix /map/org1 ("$QWC_SERVICE_PREFIX/$TENANT")"""
if self.is_multi():
return self.service_prefix + self.tenant()
return os.environ.get('TENANT_PATH_PREFIX', '@service_prefix@/@tenant@').replace('@service_prefix@', self.service_prefix).replace('@tenant@', self.tenant())
else:
return self.service_prefix
return self.service_prefix + "/"

def get_cookie_path(self, app):
# https://flask.palletsprojects.com/en/1.1.x/api/#flask.sessions.SessionInterface.get_cookie_path
Expand Down

0 comments on commit f42d553

Please sign in to comment.