From 8c8ca877d306ffe845f94fc8008c4eeb399d4185 Mon Sep 17 00:00:00 2001 From: Radu Date: Mon, 19 Sep 2022 04:08:37 +0200 Subject: [PATCH 1/3] [fix] return 404 instead of 200 for stale assets --- packages/adapter-cloudflare/src/worker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/src/worker.js b/packages/adapter-cloudflare/src/worker.js index a31267aef944..1e4c882118eb 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; } }; From 616a8ed99750fe8f7a06cb6a9055b3ec16a6c23c Mon Sep 17 00:00:00 2001 From: Radu Date: Mon, 19 Sep 2022 05:48:56 +0200 Subject: [PATCH 2/3] [chore] code format --- packages/adapter-cloudflare/src/worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/src/worker.js b/packages/adapter-cloudflare/src/worker.js index 1e4c882118eb..d3223615f2a0 100644 --- a/packages/adapter-cloudflare/src/worker.js +++ b/packages/adapter-cloudflare/src/worker.js @@ -20,7 +20,7 @@ const worker = { // static assets if (pathname.startsWith(prefix)) { res = await env.ASSETS.fetch(req); - if (!res.ok) return res + if (!res.ok) return res; const cache_control = pathname.startsWith(prefix + 'immutable/') ? 'public, immutable, max-age=31536000' From 6682e53b98a1ff9175b317b5006df0cd6d73b04c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 19 Sep 2022 12:44:48 -0400 Subject: [PATCH 3/3] Create healthy-rivers-share.md --- .changeset/healthy-rivers-share.md | 5 +++++ 1 file changed, 5 insertions(+) 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