Skip to content

Quick and dirty little script that lets you host static sites / assets on Cloudflare R2 using Cloudflare Workers

Notifications You must be signed in to change notification settings

liuyi0501/r2-workers-script

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

r2-workers-script

Description

Quick and dirty little script that lets you host static sites / assets on Cloudflare R2 using Cloudflare Workers. To take advantage of those no egress charges 🤤

What it does

  • Parses URLs to logical filenames to look up in your R2 bucket. For example:

    • Example.com will become index.html
    • Example.com/example1 will become example1.html
    • Example.com/example2/example2 will become /example2/index.html
    • Example.com/image.png will become /image.png
  • Caches found URLs in Cloudflare cache.

  • Handles 404 responses for files that don't exist.

Todo

Proper deployment using wrangler.

Installation:

  • Create R2 Bucket.
  • Create worker.
  • Link Bucket to Worker under Workers > Settings > R2 Bucket bindings. Name it MY_BUCKET
  • Assign the Worker to a route or a domain.
  • Add index.js code to Worker using the Quick edit button on the Workers Resources page.
  • Done! You can now test the Worker route / domain.

About

Quick and dirty little script that lets you host static sites / assets on Cloudflare R2 using Cloudflare Workers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%