From 235e4ce5c33ecc72520716812d8f744e6acb6628 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Thu, 24 Oct 2024 13:17:40 -0400 Subject: [PATCH] Update static handling for welcome.html to automatically load sample if the non-sample is not present, and for installed Galaxy. Fix robots.txt and favicon which were not served at all due to middleware. --- lib/galaxy/web/framework/middleware/static.py | 4 +-- lib/galaxy/webapps/base/webapp.py | 31 ++++++++++++++----- scripts/common_startup.sh | 1 - ...elcome.html.sample => welcome.sample.html} | 0 4 files changed, 24 insertions(+), 12 deletions(-) rename static/{welcome.html.sample => welcome.sample.html} (100%) diff --git a/lib/galaxy/web/framework/middleware/static.py b/lib/galaxy/web/framework/middleware/static.py index d46ff6af592c..a5d9f17d36fe 100644 --- a/lib/galaxy/web/framework/middleware/static.py +++ b/lib/galaxy/web/framework/middleware/static.py @@ -19,9 +19,7 @@ def __init__(self, directory, cache_seconds=None, directory_per_host=None): def __call__(self, environ, start_response): path_info = environ.get("PATH_INFO", "") script_name = environ.get("SCRIPT_NAME", "") - if script_name == "/robots.txt" or script_name == "/favicon.ico": - filename = script_name.replace("/", "") - elif not path_info: + if not path_info: # See if this is a static file hackishly mapped. if os.path.exists(self.directory) and os.path.isfile(self.directory): app = FileApp(self.directory) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 75a14f04e301..f2be00448f20 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -1156,19 +1156,34 @@ def build_url_map(app, global_conf, **local_conf): # Send to dynamic app by default urlmap["/"] = app - def get_static_from_config(option_name, default_path): - config_val = conf.get(option_name, default_url_path(default_path)) + def get_static_from_config(option_name, default_path, sample=None): + config_val = conf.get(option_name) + default = default_url_path(default_path) + if not config_val: + if not os.path.exists(default) and sample: + config_val = os.path.abspath(f"{sample}") + else: + config_val = default 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/") - urlmap["/images"] = get_static_from_config("static_images_dir", "static/images") - urlmap["/static/scripts"] = get_static_from_config("static_scripts_dir", "static/scripts/") - urlmap["/static/welcome.html"] = get_static_from_config("static_welcome_html", "static/welcome.html") - urlmap["/favicon.ico"] = get_static_from_config("static_favicon_dir", "static/favicon.ico") - urlmap["/robots.txt"] = get_static_from_config("static_robots_txt", "static/robots.txt") + static_dir = get_static_from_config("static_dir", "static/") + static_dir_bare = static_dir.directory.rstrip("/") + urlmap["/static"] = static_dir + urlmap["/images"] = get_static_from_config("static_images_dir", f"{static_dir_bare}/images") + urlmap["/static/scripts"] = get_static_from_config("static_scripts_dir", f"{static_dir_bare}/scripts/") + + urlmap["/static/welcome.html"] = get_static_from_config( + "static_welcome_html", f"{static_dir_bare}/welcome.html", sample=default_url_path("static/welcome.sample.html") + ) + urlmap["/favicon.ico"] = get_static_from_config( + "static_favicon_dir", f"{static_dir_bare}/favicon.ico", sample=default_url_path("static/favicon.ico") + ) + urlmap["/robots.txt"] = get_static_from_config( + "static_robots_txt", f"{static_dir_bare}/robots.txt", sample=default_url_path("static/robots.txt") + ) if "static_local_dir" in conf: urlmap["/static_local"] = Static(conf["static_local_dir"], cache_time) diff --git a/scripts/common_startup.sh b/scripts/common_startup.sh index e1fa46fdbac6..20a9b0ea29c1 100755 --- a/scripts/common_startup.sh +++ b/scripts/common_startup.sh @@ -34,7 +34,6 @@ done SAMPLES=" tool-data/shared/ucsc/builds.txt.sample tool-data/shared/ucsc/manual_builds.txt.sample - static/welcome.html.sample " RMFILES=" diff --git a/static/welcome.html.sample b/static/welcome.sample.html similarity index 100% rename from static/welcome.html.sample rename to static/welcome.sample.html