diff --git a/services/api-server/src/api_server/main.py b/services/api-server/src/api_server/main.py index 81f1234..140f141 100644 --- a/services/api-server/src/api_server/main.py +++ b/services/api-server/src/api_server/main.py @@ -135,7 +135,16 @@ from ui_semantics import form_semantics app = FastAPI(title="SFERA API", version="0.1.0") _HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5" -app.mount("/html5/assets", StaticFiles(directory=_HTML5_ASSETS_DIR), name="html5-assets") + + +class Html5StaticFiles(StaticFiles): + def file_response(self, *args, **kwargs): + response = super().file_response(*args, **kwargs) + response.headers.setdefault("Cache-Control", "public, max-age=3600") + return response + + +app.mount("/html5/assets", Html5StaticFiles(directory=_HTML5_ASSETS_DIR), name="html5-assets") app.add_middleware( CORSMiddleware, allow_origin_regex=os.environ.get( diff --git a/services/api-server/tests/test_api.py b/services/api-server/tests/test_api.py index 2bd4467..74936af 100644 --- a/services/api-server/tests/test_api.py +++ b/services/api-server/tests/test_api.py @@ -257,14 +257,17 @@ def test_html5_server_rendered_project_editor(tmp_path: Path): htmx_asset = client.get("/html5/assets/htmx.min.js") assert htmx_asset.status_code == 200 assert "javascript" in htmx_asset.headers["content-type"] + assert htmx_asset.headers["cache-control"] == "public, max-age=3600" assert "htmx" in htmx_asset.text sse_asset = client.get("/html5/assets/htmx-ext-sse.js") assert sse_asset.status_code == 200 assert "javascript" in sse_asset.headers["content-type"] + assert sse_asset.headers["cache-control"] == "public, max-age=3600" assert "sse" in sse_asset.text css_asset = client.get("/html5/assets/html5.css") assert css_asset.status_code == 200 assert "text/css" in css_asset.headers["content-type"] + assert css_asset.headers["cache-control"] == "public, max-age=3600" assert ".workspace" in css_asset.text