Skip to content

Commit

Permalink
Update static handling for welcome.html to automatically load sample if
Browse files Browse the repository at this point in the history
the non-sample is not present, and for installed Galaxy. Fix robots.txt
and favicon which were not served at all due to middleware.
  • Loading branch information
natefoo committed Oct 24, 2024
1 parent bbc8dd6 commit 235e4ce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 1 addition & 3 deletions lib/galaxy/web/framework/middleware/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 23 additions & 8 deletions lib/galaxy/webapps/base/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion scripts/common_startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
File renamed without changes.

0 comments on commit 235e4ce

Please sign in to comment.