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; } };