fix(server): limit immutable media cache headers

This commit is contained in:
Amruth Pillai
2026-07-28 08:31:26 +02:00
parent a2901bfb2e
commit dd0531091b
2 changed files with 9 additions and 1 deletions
+8
View File
@@ -86,6 +86,14 @@ describe("web app fallback classification", () => {
});
expect(headers.get("Cache-Control")).toBe("public, max-age=31536000, immutable");
const unversionedHeaders = new Headers();
await staticOptions?.onFound?.("", {
req: { path: "/videos/timelapse.mp4" },
header: (name, value) => unversionedHeaders.set(name, value),
});
expect(unversionedHeaders.get("Cache-Control")).toBeNull();
});
it.each(["/", "/alice/resume"])("sets framing and report-only CSP security headers on %s", async (pathname) => {
+1 -1
View File
@@ -161,7 +161,7 @@ function createRootSeoMarkup(canonicalUrl: string) {
export const serveWebDistStatic = serveStatic({
root: staticRoot,
onFound: (_path, context) => {
if (context.req.path.startsWith("/videos/")) {
if (/^\/videos\/.*-v\d+\.(?:mp4|webp)$/.test(context.req.path)) {
context.header("Cache-Control", "public, max-age=31536000, immutable");
}
},