Skip to content

[wrangler][miniflare] Serve local R2 bucket objects publicly via /cdn-cgi/mf/r2#14119

Open
tahmid-23 wants to merge 3 commits into
cloudflare:mainfrom
tahmid-23:r2-local-public-bucket
Open

[wrangler][miniflare] Serve local R2 bucket objects publicly via /cdn-cgi/mf/r2#14119
tahmid-23 wants to merge 3 commits into
cloudflare:mainfrom
tahmid-23:r2-local-public-bucket

Conversation

@tahmid-23
Copy link
Copy Markdown

@tahmid-23 tahmid-23 commented May 29, 2026

This implements the idea discussed in #13325.

R2 exposes a public endpoint for accessing buckets remotely, but no such analogue exists in local development.

This adds a configuration parameter, experimental_local_port, that sets up a socket for a given R2 binding. This is sent to a custom worker, which translates a GET/HEAD request into an R2 access. The worker provides full support for range and condition headers.

As a brief aside, I'd like to implement S3-compatible pre-signed uploads in the newly created worker in a follow-up PR.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: I will make a docs PR if this PR is considered for acceptance.

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 85bbe76

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
miniflare Minor
wrangler Minor
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
@cloudflare/wrangler-bundler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod workers-devprod requested review from a team and NuroDev and removed request for a team May 29, 2026 23:08
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented May 29, 2026

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/r2-local-public-bucket-miniflare.md: [@cloudflare/wrangler]
  • .changeset/r2-local-public-bucket-wrangler.md: [@cloudflare/wrangler]
  • packages/miniflare/README.md: [@cloudflare/wrangler]
  • packages/miniflare/src/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/r2/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/shared/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/r2/local.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/r2/local.spec.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/environment.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/worker.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/startDevWorker/MultiworkerRuntimeController.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/dev/miniflare/index.ts: [@cloudflare/wrangler]

@tahmid-23 tahmid-23 force-pushed the r2-local-public-bucket branch 2 times, most recently from 5de38c1 to 3bd48b7 Compare May 30, 2026 00:19
@NuroDev
Copy link
Copy Markdown
Member

NuroDev commented Jun 4, 2026

Thank you for this PR @tahmid-23.
After speaking with the team on this, we believe the better approach for this change wold be to expose these routes under the /cdn-cgi/mf/r2/... path, similar to the changes made in #13234, rather than exposing a whole new port to serve on.

@tahmid-23
Copy link
Copy Markdown
Author

@NuroDev makes sense.
Can I implement that myself here, or would you rather it stay under your team?

@NuroDev
Copy link
Copy Markdown
Member

NuroDev commented Jun 4, 2026

Can I implement that myself here, or would you rather it stay under your team?

Feel free to implement that yourself here, and if we can help with anything let us know 😄

@tahmid-23 tahmid-23 force-pushed the r2-local-public-bucket branch from 3bd48b7 to 12cdc58 Compare June 4, 2026 23:26
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Jun 4, 2026

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/r2-local-public-bucket-miniflare.md: [@cloudflare/wrangler]
  • .changeset/r2-local-public-bucket-wrangler.md: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/core/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/r2/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/constants.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/entry.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/r2/local.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/r2/local.spec.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/environment.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/worker.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/dev/miniflare/index.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

@tahmid-23 tahmid-23 force-pushed the r2-local-public-bucket branch 4 times, most recently from cea5c3f to eca9313 Compare June 5, 2026 00:20
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 9 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/workers-utils/src/config/environment.ts Outdated
tahmid-23 and others added 3 commits June 4, 2026 20:28
Accept and validate the experimental_local_public boolean on R2 bucket
bindings in wrangler config. Gated as experimental. No runtime behavior
attached yet — wiring lands in the next commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replaces the use of the shared `namespaceEntries` helper in the R2 plugin
with a local `r2BucketEntries` typed against `R2OptionsSchema`. No behavior
change — the new helper produces the same shape — but a local helper lets
future R2-specific fields be threaded through without expanding the shared
helper used by other namespace-style plugins.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…-cgi/mf/r2

Exposes opted-in local R2 buckets at <dev-server>/cdn-cgi/mf/r2/<binding>/<key>
on the existing user-facing dev server, dispatched through the entry worker
(same pattern as the stream binding). Subject to the existing /cdn-cgi/*
Host/Origin allowlist. Enabled per-binding via experimental_local_public: true
on R2 bindings in wrangler config.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tahmid-23 tahmid-23 force-pushed the r2-local-public-bucket branch from eca9313 to 85bbe76 Compare June 5, 2026 00:28
@tahmid-23
Copy link
Copy Markdown
Author

@NuroDev done
I rewrote the history to reduce the code churn

@tahmid-23 tahmid-23 changed the title [wrangler][miniflare] Serve local R2 bucket objects publicly over a dedicated port [wrangler][miniflare] Serve local R2 bucket objects publicly via /cdn-cgi/mf/r2 Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants