Skip to content

Commit ccccde3

Browse files
committed
Resolve static files using importlib_resources for crfm-proxy-server
1 parent 2b2f740 commit ccccde3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/helm/proxy/server.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from urllib.parse import unquote_plus
77
import argparse
88
import dataclasses
9+
import importlib_resources as resources
910
import json
1011
import os
1112
import sys
@@ -86,7 +87,7 @@ def handle_root():
8687

8788
@app.get("/static/<filename:path>")
8889
def handle_static_filename(filename):
89-
resp = bottle.static_file(filename, root=os.path.join(os.path.dirname(__file__), "static"))
90+
resp = bottle.static_file(filename, root=app.config["helm.staticpath"])
9091
resp.add_header("Cache-Control", "no-store, must-revalidate ")
9192
return resp
9293

@@ -284,6 +285,12 @@ def main():
284285
ensure_directory_exists(sqlite_cache_path)
285286
cache_backend_config = SqliteCacheBackendConfig(sqlite_cache_path)
286287

288+
static_package_name = "helm.proxy.static"
289+
resource_path = resources.files(static_package_name).joinpath("index.html")
290+
with resources.as_file(resource_path) as resource_filename:
291+
static_path = str(resource_filename.parent)
292+
app.config["helm.staticpath"] = static_path
293+
287294
service = ServerService(base_path=args.base_path, cache_backend_config=cache_backend_config)
288295

289296
gunicorn_args = {

0 commit comments

Comments
 (0)