Skip to content

Fix local dev R2 binding so published images preview correctly - #135

Open
ianmuchyri wants to merge 1 commit into
mainfrom
fix/local-dev-r2-remote-binding
Open

ianmuchyri wants to merge 1 commit into
mainfrom
fix/local-dev-r2-remote-binding

Conversation

@ianmuchyri

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the equivalent fix in magistrala-docs: absmach/magistrala-docs#171

Previously, once an image was published to the shared websites-images R2 bucket via scripts/publish-image.mjs, there was no way to actually preview it locally:

  • pnpm run dev (plain next dev) has zero knowledge of wrangler.jsonc / the Worker, so it always 404s on doc images (expected, not fixed here).
  • wrangler dev runs the real Worker, but its R2 binding defaulted to an empty local simulated bucket, not the real one, so published images still 404'd.
  • Worse, the wrangler version pinned in package.json (^4.81.1) falls in a range with a real bug: a remote R2 binding throws SyntaxError: Unexpected end of JSON input instead of proxying to R2 at all. Confirmed fixed at wrangler 4.120.0.

Three changes:

  1. wrangler.jsonc: add "remote": true to the IMAGES_BUCKET R2 binding, so wrangler dev proxies to the real bucket instead of an empty local simulator. Confirmed via wrangler's own config-schema.json that this field is local-dev-only and has no effect on the deployed Worker.
  2. package.json: bump wrangler devDependency from ^4.81.1 to ^4.120.0, with pnpm-lock.yaml updated accordingly (pnpm install also added two minimumReleaseAgeExclude entries to pnpm-workspace.yaml for wrangler@4.120.0 and miniflare@5.20260801.1-alpha, a pnpm supply-chain-age guard needed to resolve those versions).
  3. scripts/README.md: new "Previewing images locally" section (placed after "Publishing an image", before "Bulk-uploading via the R2 dashboard") documenting the pnpm run build && npx wrangler dev workflow, the "remote": true binding, and the wrangler version requirement.

Test plan

  • pnpm install — lockfile updated, ./node_modules/.bin/wrangler --version reports 4.120.0
  • pnpm run types:check — passes (this repo's script also runs wrangler types)
  • pnpm run build — succeeds, produces ./out
  • npx wrangler dev — startup banner shows env.IMAGES_BUCKET (websites-images) R2 Bucket remote (mode = remote, not local); no SyntaxError crash
  • Homepage returns 200 (/ redirects 301 to /docs/cocos-ai/, which returns 200 — that's this site's existing basePath redirect, unrelated to this change)
  • Hit a real doc image path (/docs/cocos-ai/img/agent/overview.png) through the running wrangler dev — after the "Establishing remote connection" phase settled, it returned the actual PNG bytes from the real bucket

wrangler dev previously used an empty local-simulated R2 bucket for
IMAGES_BUCKET, so images published via publish-image.mjs still 404'd
locally. Add "remote": true to the R2 binding in wrangler.jsonc so
wrangler dev proxies to the real websites-images bucket instead.

This requires wrangler >= 4.120.0 -- the previously pinned ^4.81.1
range has a bug where a remote R2 binding throws
"SyntaxError: Unexpected end of JSON input" instead of proxying to
R2, confirmed fixed at 4.120.0. Bump the wrangler devDependency and
update the lockfile accordingly.

Also document the local preview workflow in scripts/README.md.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
cocos-docs 857a6ee Commit Preview URL

Branch Preview URL
Aug 07 2026, 04:53 PM

This branch has not been deployed

No deployments
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.

1 participant