examples/storefront Public
id: 0002-serve-images-through-the-api
type: decision
owner: justin
status: accepted
reviewed: 2026-10-01
0002 Serve images through storefront-api
Context
Product images are in R2 (see [[product-images]]). Browsers need a URL for each one. R2 can serve a bucket publicly, on its r2.dev subdomain or a custom domain, or a Worker can read the object and return it.
Decision
storefront-api serves images at GET /images/<key>. The bucket stays private.
Consequences
- One hostname for the whole shop while we are still on workers.dev, and nothing to set up in DNS.
- Only keys under
products/are reachable, whatever else ends up in the bucket. - Every image request runs the Worker, even though the response is the same for a year. That is fine at launch traffic. If image requests start to dominate the Worker's requests, move them to a custom domain on the bucket.