r2-serve

Nginx-style directory listings for Cloudflare Workers and R2.

GitHub · npm · live example bucket

What this example shows

Minimal Worker

import { createAutoIndexWorker } from "r2-serve";

export interface Env {
  BUCKET: R2Bucket;
}

export default createAutoIndexWorker<Env>({
  bucket: (env) => env.BUCKET,
  indexes: ["index.html", "index.htm"],
});

Cloudflare resources

A deployment needs an R2 bucket, a Queue, R2 event notification rules for object creates/deletes, and a Worker with the R2 binding plus Queue consumer.

The Terraform module in the repository can manage the whole standalone deployment using the committed Worker bundle.