Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 404 instead of 200 for stale assets with adapter-cloudflare #6879

Merged
merged 4 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-rivers-share.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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