From 1765ed7c6d8ab2b5c318a5f839e8ed9e27338ac8 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 25 Aug 2021 11:44:16 -0400 Subject: [PATCH] per host configurable static site configs --- lib/galaxy/web/framework/middleware/static.py | 14 ++++++++++++-- lib/galaxy/webapps/base/webapp.py | 4 +++- lib/galaxy/webapps/galaxy/config_schema.yml | 6 ++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/static.py b/lib/galaxy/web/framework/middleware/static.py index d8aba84921d..65213d7af8b 100644 --- a/lib/galaxy/web/framework/middleware/static.py +++ b/lib/galaxy/web/framework/middleware/static.py @@ -8,9 +8,10 @@ from paste.urlparser import StaticURLParser class CacheableStaticURLParser(StaticURLParser): - def __init__(self, directory, cache_seconds=None): + def __init__(self, directory, cache_seconds=None, directory_per_host=None): StaticURLParser.__init__(self, directory) self.cache_seconds = cache_seconds + self.directory_per_host = directory_per_host def __call__(self, environ, start_response): path_info = environ.get('PATH_INFO', '') @@ -27,7 +28,16 @@ class CacheableStaticURLParser(StaticURLParser): filename = 'index.html' else: filename = request.path_info_pop(environ) - full = os.path.join(self.directory, filename) + + directory = self.directory + host = environ.get('HTTP_HOST') + if self.directory_per_host and host: + for host_key, host_val in self.directory_per_host.items(): + if host_key in host: + directory = host_val + break + + full = os.path.join(directory, filename) if not os.path.exists(full): return self.not_found(environ, start_response) if os.path.isdir(full): diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index c0adbab0d1c..82d9c7c2873 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -1011,7 +1011,9 @@ def build_url_map(app, global_conf, local_conf): def get_static_from_config(option_name, default_path): config_val = conf.get(option_name, default_url_path(default_path)) - return Static(config_val, cache_time) + per_host_config_option = f"{option_name}_by_host" + per_host_config = conf.get(per_host_config_option) + return Static(config_val, cache_time, directory_per_host=per_host_config) # Define static mappings from config urlmap["/static"] = get_static_from_config("static_dir", "static/") diff --git a/lib/galaxy/webapps/galaxy/config_schema.yml b/lib/galaxy/webapps/galaxy/config_schema.yml index 3a42699e711..67b5e701d54 100644 --- a/lib/galaxy/webapps/galaxy/config_schema.yml +++ b/lib/galaxy/webapps/galaxy/config_schema.yml @@ -1479,6 +1479,7 @@ mapping: static_dir: type: str default: static/ + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a @@ -1489,6 +1490,7 @@ mapping: static_images_dir: type: str default: static/images + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a @@ -1499,6 +1501,7 @@ mapping: static_favicon_dir: type: str default: static/favicon.ico + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a @@ -1509,6 +1512,7 @@ mapping: static_scripts_dir: type: str default: static/scripts/ + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a @@ -1519,6 +1523,7 @@ mapping: static_style_dir: type: str default: static/style + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a @@ -1529,6 +1534,7 @@ mapping: static_robots_txt: type: str default: static/robots.txt + per_host: true required: false desc: | Serve static content, which must be enabled if you're not serving it via a