Fix cache bypass scope bug causing 500 error
Some checks failed
TypeScript CI / build (push) Successful in 31s
Deploy to R2 / deploy (push) Has been cancelled

response variable was scoped inside if(!bypassCache) block but referenced
outside. Changed to const response in the R2 fetch section and conditionally
cache based on bypassCache flag.
This commit is contained in:
Heimdall
2026-04-01 07:11:15 +00:00
parent b5595a4aef
commit 86bf2a9b0e

View File

@@ -588,12 +588,17 @@ export default {
headers.set('ETag', object.etag);
}
response = new Response(object.body, { headers });
const response = new Response(object.body, { headers });
ctx.waitUntil(Promise.all([
cache.put(cacheKey, response.clone()),
recordUsage(env, customer, object.size)
]));
// 캐시 바이패스가 아닌 경우에만 캐시에 저장
if (!bypassCache) {
ctx.waitUntil(Promise.all([
cache.put(cacheKey, response.clone()),
recordUsage(env, customer, object.size)
]));
} else {
ctx.waitUntil(recordUsage(env, customer, object.size));
}
return response;