A secure image serving application built with React Router v7 and Cloudflare Workers, using R2 for storage.
- 🖼️ Direct image serving at
https://yourdomain.com/image.png - 🔒 Password-protected admin panel
- 📁 File upload with support for all file types
- 🗂️ Image management with preview, file info, and deletion
- ☁️ Powered by Cloudflare R2 storage
- ⚡ Fast edge deployment with Cloudflare Workers
/- Home page with usage information/manage- Admin panel for managing images (password protected)/:filename- Direct file serving (e.g.,/image.png,/document.pdf)
-
Clone and install dependencies:
bun install
-
Configure environment:
- Copy
.env.exampleto.env - Set your
ADMIN_PASSWORDin.env
- Copy
-
Set up Cloudflare R2:
- Create an R2 bucket named
image-servingin your Cloudflare dashboard - Update
wrangler.jsoncif needed
- Create an R2 bucket named
-
Development:
bun dev
-
Deploy:
bun run deploy
Images are served directly at the root path:
https://yourdomain.com/photo.jpg- Original imagehttps://yourdomain.com/document.pdf- Any file type
Add query parameters for image processing:
Predefined Sizes:
?size=thumb- Thumbnail (150x150, cropped)?size=small- Small (300x300 max, scaled)?size=medium- Medium (600x600 max, scaled)?size=large- Large (1200x1200 max, scaled)?size=800x600- Custom dimensions
Advanced Parameters:
?width=400- Specific width?height=300- Specific height?quality=80- JPEG quality (1-100, default: 85)?format=webp- Convert format (webp, avif, jpeg, png)
Examples:
https://yourdomain.com/photo.jpg?size=medium
https://yourdomain.com/photo.jpg?width=500&quality=90
https://yourdomain.com/photo.jpg?size=thumb&format=webp
https://yourdomain.com/photo.jpg?size=800x600&quality=95&format=webp
Note: Image transformation parameters are parsed and prepared for processing. To enable actual image resizing, you'll need to integrate with Cloudflare Images or implement server-side image processing. Currently, the original image is served with transformation metadata in headers.
- Go to
https://yourdomain.com/manage - Enter your admin password
- Upload new files or manage existing ones
ADMIN_PASSWORD- Password for the admin panel (set in.envfile)
- Admin password is stored securely in environment variables
- No sensitive data is exposed in the codebase
- File access is controlled through Cloudflare R2 permissions
- React Router v7 - Full-stack React framework
- Cloudflare Workers - Edge runtime
- Cloudflare R2 - Object storage
- TypeScript - Type safety
- Tailwind CSS - Styling
- Bun - JavaScript runtime and package manager
A modern, production-ready template for building full-stack React applications using React Router.
- 🚀 Server-side rendering
- ⚡️ Hot Module Replacement (HMR)
- 📦 Asset bundling and optimization
- 🔄 Data loading and mutations
- 🔒 TypeScript by default
- 🎉 TailwindCSS for styling
- 📖 React Router docs
Install the dependencies:
npm installStart the development server with HMR:
npm run devYour application will be available at http://localhost:5173.
Preview the production build locally:
npm run previewCreate a production build:
npm run buildDeployment is done using the Wrangler CLI.
To build and deploy directly to production:
npm run deployTo deploy a preview URL:
npx wrangler versions uploadYou can then promote a version to production after verification or roll it out progressively.
npx wrangler versions deployThis template comes with Tailwind CSS already configured for a simple default starting experience. You can use whatever CSS framework you prefer.
Built with ❤️ using React Router.