For Workers & Pages, what is the name of the domain?
What is the issue or error you’re encountering
I have a worker that retrieves images from my R2 bucket. I have assigned a CNAME record (cdn.example.com
) to the worker’s domain (and setted Cloudflare as a proxy). When making a request to cdn.example.com
, cf-cache-status
header does not appear in the response. I also tried creating a cache rule for that hostname, but still nothing.
What are the steps to reproduce the issue?
Make a request to cdn.example.com/image-example.png
.
Get the image correctly, but see the following headers:
HTTP/2 200
date: Sat, 24 May 2025 01:28:44 GMT
content-type: image/jpeg
content-length: 1014662
server: cloudflare
vary: Accept-Encoding
cf-ray: 9449049e2b1e0321-MAD
cache-control: public, max-age=31536000
report-to: {“endpoints”:[{“url”:“https://a.nel.cloudflare.com/report/v4?s=%2BY24AYmLZ8Ug8iz%2BFON%2B%2BmDe3UfDXp4UB%2BJGIQoSLy27Uyr3n7dL23tc0X3Uud2ueQXYmeuhMM2W7l4sEMkNkFeL7YJjw48F7cANZ%2Fr8vjeFD3SN6kc2F9BF%2BSfa4dc1wUk%3D”}],“group”:“cf-nel”,“max_age”:604800}
nel: {“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}
alt-svc: h3=“:443”; ma=86400
server-timing: cfL4;desc=“?proto=TCP&rtt=6310&min_rtt=4745&rtt_var=1914&sent=8&recv=10&lost=0&retrans=0&sent_bytes=3498&recv_bytes=2431&delivery_rate=611025&cwnd=230&unsent_bytes=0&cid=52421ab3d8d37864&ts=471&x=0”
X-Firefox-Spdy: h2
This is my worker code:
export default { async fetch(request, env) { try { // Rate limiting const clientIP = request.headers.get('cf-connecting-ip') const rateLimitKey =
ratelimit:${clientIP}`
// Get and increment counter
const currentRequests = parseInt((await env.KV.get(rateLimitKey)) || '0')
if (currentRequests > 100) {
return new Response('Rate limit exceeded', { status: 429 })
}
// Set counter with 60 second expiration
await env.KV.put(rateLimitKey, (currentRequests + 1).toString(), {
expirationTtl: 60,
})
const url = new URL(request.url)
const path = url.pathname.slice(1)
const object = await env.MY_BUCKET.get(path)
if (!object) {
return new Response('Image not found', { status: 404 })
}
const headers = new Headers()
headers.set('Cache-Control', 'public, max-age=31536000')
headers.set('Content-Type', object.httpMetadata.contentType || 'image/jpeg')
return new Response(object.body, {
headers,
})
} catch (err) {
if (!(err instanceof Error)) {
throw new Error(`Was thrown a non-error: ${err}`)
}
console.error('Error serving image:', err)
return new Response('Error processing image', {
status: 500,
headers: {
'Content-Type': 'text/plain',
},
})
}
},
}
`
Can someone help me on what I am doing wrong? First of all, sorry if the solution is simple, I am new to this and still learning, haha