From ae2e4bf2c5fe0aeba4cba21d51362837f66d1949 Mon Sep 17 00:00:00 2001 From: Radu <64026120+raduab@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:45:28 +0200 Subject: [PATCH] fix: return 404 instead of 200 for stale assets with `adapter-cloudflare` (#6879) * [fix] return 404 instead of 200 for stale assets * [chore] code format * Create healthy-rivers-share.md Co-authored-by: Rich Harris --- .changeset/healthy-rivers-share.md | 5 +++++ packages/adapter-cloudflare/src/worker.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/healthy-rivers-share.md diff --git a/.changeset/healthy-rivers-share.md b/.changeset/healthy-rivers-share.md new file mode 100644 index 000000000000..8aac9d659437 --- /dev/null +++ b/.changeset/healthy-rivers-share.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/adapter-cloudflare": patch +--- + +[fix] return 404 instead of 200 for missing assets diff --git a/packages/adapter-cloudflare/src/worker.js b/packages/adapter-cloudflare/src/worker.js index a31267aef944..d3223615f2a0 100644 --- a/packages/adapter-cloudflare/src/worker.js +++ b/packages/adapter-cloudflare/src/worker.js @@ -20,6 +20,7 @@ const worker = { // static assets if (pathname.startsWith(prefix)) { res = await env.ASSETS.fetch(req); + if (!res.ok) return res; const cache_control = pathname.startsWith(prefix + 'immutable/') ? 'public, immutable, max-age=31536000' @@ -65,7 +66,7 @@ const worker = { // Writes to Cache only if allowed & specified pragma = res.headers.get('cache-control'); - return pragma ? Cache.save(req, res, context) : res; + return pragma && res.ok ? Cache.save(req, res, context) : res; } };