A small Cloudflare Worker (Hono + TypeScript) that sits over a public R2 bucket served by a custom domain with Cloudflare Image Transformations enabled.
GET /— health check, returns{ ok: true }.GET /search?prefix=<path>— lists every object in the bucket. Optionalprefixquery filter. Returns{ prefix, count, results: [{ key, url }] }, whereurlis the public URL on the custom domain.GET /ui— interactive HTML page for building Cloudflare Image Transformation URLs: pick an image, tweak sizing/quality/format/effects, see a live preview, copy the URL.
cp wrangler.example.toml wrangler.toml
# edit wrangler.toml and set your bucket names
echo 'PUBLIC_BUCKET_URL=https://img.example.com' > .dev.vars
npm install
npm run dev # http://localhost:8787wrangler.toml and .dev.vars are gitignored — each environment fills them in locally.
| Name | Where | Purpose |
|---|---|---|
BUCKET |
wrangler.toml → [[r2_buckets]] |
R2 binding used by /search to list keys |
PUBLIC_BUCKET_URL |
.dev.vars (local) / wrangler secret put (prod) |
Custom domain fronting the bucket, no trailing slash |
npm run dev— run locally with Wranglernpm run deploy— deploy to Cloudflarenpm run typecheck—tsc --noEmit
wrangler secret put PUBLIC_BUCKET_URL # first time only
npm run deploy