Skip to content

emilienbidet/cloudflare-r2-dev-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare R2 Dev Server

This is a workaround solution to serve Cloudlflare R2 images when developping locally. Made with Bun and Hono.

Waiting for this feature from wrangler: cloudflare/workers-sdk#3687

How to setup?

Clone the repo at the root of your project.

git clone https://github.com/emilienbidet/cloudflare-r2-dev-server

Install dependencies:

cd cloudflare-r2-dev-server
bun install

Setup env variables in a .env file, grab them from .wrangler directory :

This is a example .env file:

R2_BUCKET_NAME="kuma"
R2_BUCKET_DABASE_NAME="4728dfd2675ad89b0cdad6672d49dacf952327a5040562ad905e0baa743495c6"
R2_BUCKET_PATH="../.wrangler/state/v3/r2/"
PORT="3000" # optional

Start the server

bun run start

Test it by uploading a image to the bucket and by trying access it with http://localhost:3000/:key

🎉 Bravo! All your uploaded r2 images when developping locally are now available from http://localhost:3000/:key

Optional

Add cloudflare-r2-dev-server/ to your .gitignore file

Add cloudflare-r2-dev-server to your tsconfig.json file

{
 "exclude": [
    "node_modules",
    "dist",
    "cloudflare-r2-dev-server"
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors