Skip to content

[wrangler][miniflare] Serve local R2 bucket objects publicly over a dedicated port#14119

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

[wrangler][miniflare] Serve local R2 bucket objects publicly over a dedicated port#14119
tahmid-23 wants to merge 2 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)

Introduce an `UnsafePluginSocketRequest` mechanism so plugins can request a
dedicated HTTP socket fronting one of their services, bypassing Miniflare's
entry worker. Plugins return these via `unsafeSockets` on `ServicesExtensions`,
and Miniflare opens the requested socket and tracks it by user binding name.

A new `getPublicSocketURL(bindingName)` method on the `Miniflare` class returns
the URL of the socket serving a given binding, which is useful when the socket
was requested on port `0` and the assigned port isn't known ahead of time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 3bd48b7

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

This PR includes changesets to release 5 packages
Name Type
miniflare Minor
wrangler Minor
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers 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 from 0de4635 to 5de38c1 Compare May 30, 2026 00:13
…edicated port

Add an `experimental_local_port` option to R2 bucket bindings. When set, the
bucket's objects are served over plain HTTP on a dedicated port during local
development, simulating a public R2 bucket. This wires the config field through
wrangler dev into Miniflare's R2 plugin, which uses the per-binding socket
mechanism to front a new `public.worker` over the requested port. A warning is
logged with the public URL so users know the bucket is exposed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tahmid-23 tahmid-23 force-pushed the r2-local-public-bucket branch from 5de38c1 to 3bd48b7 Compare May 30, 2026 00:19
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.

2 participants