Skip to content

Commit

Permalink
fix: return 404 instead of 200 for stale assets with `adapter-cloudfl…
Browse files Browse the repository at this point in the history
…are` (#6879)

* [fix] return 404 instead of 200 for stale assets

* [chore] code format

* Create healthy-rivers-share.md

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
raduab and Rich-Harris committed Sep 19, 2022
1 parent 2ae753a commit ae2e4bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/healthy-rivers-share.md
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-cloudflare": patch
---

[fix] return 404 instead of 200 for missing assets
3 changes: 2 additions & 1 deletion packages/adapter-cloudflare/src/worker.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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;
}
};

Expand Down

0 comments on commit ae2e4bf

Please sign in to comment.