A lightweight Cloudflare Worker that proxies a Cloudflare R2 bucket as
an image CDN at img.mrdemonwolf.com. It handles serving, uploading,
and deleting images with strict CORS controls and aggressive caching.
Built to keep image delivery fast and infrastructure simple.
- R2 proxying — Serves objects directly from a bound R2 bucket with
correct
Content-Typeheaders. - Aggressive caching — All served objects carry
Cache-Control: public, max-age=31536000, immutablefor edge and browser caching. - CORS enforcement — Restricts
Access-Control-Allow-Origintomrdemonwolf.comandwww.mrdemonwolf.comonly. - Upload support —
PUTrequests write objects to R2 and preserve the incomingContent-Type. - Key normalisation — Accepts paths with or without the bucket-name
prefix (
/shottr/foo.pngand/foo.pngboth resolve to the same object). - Delete support —
DELETErequests remove objects from R2.
- Install dependencies:
npm install
- Authenticate with Cloudflare:
npx wrangler login
- Start the local dev server:
npm run dev
| Layer | Technology |
|---|---|
| Runtime | Cloudflare Workers |
| Storage | Cloudflare R2 |
| Language | TypeScript (ESNext) |
| Tooling | Wrangler v3 |
- Node.js 18 or later
- A Cloudflare account with R2 enabled
- Wrangler v3 (
npm installpulls it as a dev dependency)
- Clone the repository and install dependencies:
npm install
- Confirm the R2 bucket binding in
wrangler.tomlmatches your Cloudflare account:[[r2_buckets]] binding = "BUCKET" bucket_name = "shottr"
- Start local development:
npm run dev
- Deploy to production:
npm run deploy
npm run dev— Runs the worker locally viawrangler dev.npm run deploy— Builds and deploys the worker to Cloudflare.
- TypeScript strict mode enabled (
noEmit,strict,ESNexttarget). @cloudflare/workers-typesfor accurate R2 and Workers type definitions.
.
├── src/
│ └── index.ts # Worker entry point (all request handling)
├── wrangler.toml # Cloudflare Worker config, routes, and R2 binding
├── tsconfig.json # TypeScript compiler options
└── package.json # Scripts and dev dependencies
Questions or feedback? Join my server
Made with love by MrDemonWolf, Inc.