Skip to content

Commit ae2e4bf

Browse files
raduabRich-Harris
andauthored
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 <[email protected]>
1 parent 2ae753a commit ae2e4bf

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/healthy-rivers-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/adapter-cloudflare": patch
3+
---
4+
5+
[fix] return 404 instead of 200 for missing assets

packages/adapter-cloudflare/src/worker.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const worker = {
2020
// static assets
2121
if (pathname.startsWith(prefix)) {
2222
res = await env.ASSETS.fetch(req);
23+
if (!res.ok) return res;
2324

2425
const cache_control = pathname.startsWith(prefix + 'immutable/')
2526
? 'public, immutable, max-age=31536000'
@@ -65,7 +66,7 @@ const worker = {
6566

6667
// Writes to Cache only if allowed & specified
6768
pragma = res.headers.get('cache-control');
68-
return pragma ? Cache.save(req, res, context) : res;
69+
return pragma && res.ok ? Cache.save(req, res, context) : res;
6970
}
7071
};
7172

0 commit comments

Comments
 (0)