Skip to content

Make published R2 images visible in local dev (stacked on feat/r2-image-cdn) - #16

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

Make published R2 images visible in local dev (stacked on feat/r2-image-cdn)#16
ianmuchyri wants to merge 1 commit into
feat/r2-image-cdnfrom
fix/local-dev-r2-remote-binding

Conversation

@ianmuchyri

Copy link
Copy Markdown
Contributor

Stacked PR — depends on #feat/r2-image-cdn

This branches off feat/r2-image-cdn (not main) because that branch — which introduces the wrangler.jsonc r2_buckets binding, scripts/publish-image.mjs, scripts/README.md, and the image-proxy Worker — is not yet merged. This PR cannot merge before feat/r2-image-cdn does, and should be reviewed with that in mind (the diff below is only the incremental fix on top of it).

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

Summary

  • Add "remote": true to the IMAGES_BUCKET R2 binding in wrangler.jsonc so wrangler dev connects to the real websites-images bucket instead of an empty local simulator — images published via publish-image.mjs now render locally without manually seeding local R2 state. Confirmed via the installed wrangler's own config-schema.json that this field is local-dev-only and has no effect on the deployed Worker.
  • Bump the wrangler devDependency ^4.95.0^4.120.0 (and update pnpm-lock.yaml accordingly): the older version has a bug where a remote R2 binding throws SyntaxError: Unexpected end of JSON input instead of actually proxying to R2, which is what made this look broken in the first place.
  • Add a "Previewing images locally" section to scripts/README.md (right after "Publishing an image") documenting that wrangler dev — not wrangler pages dev — is the correct local preview command, since this repo deploys via plain wrangler deploy (Workers + static assets), not Pages.

Test plan

  • pnpm run build && npx wrangler dev (with CLOUDFLARE_ACCOUNT_ID set to the account owning websites-images, since the token has access to more than one account) — startup banner shows env.IMAGES_BUCKET (websites-images) R2 Bucket remote, confirming binding mode is remote, not local
  • Homepage (/) returns 200 (redirects to /docs/hardware/)
  • All 13 images currently referenced via the new /img/<file> MDX convention across content/docs/** return 200 with correct image/png/image/svg+xml content and byte-identical payload to a direct wrangler r2 object get --remote download (verified baseboard-front.png, 119040 bytes)
  • A nonexistent image path returns a clean 404 (not a crash)
  • No SyntaxError: Unexpected end of JSON input at any point
  • ./node_modules/.bin/wrangler --version reports 4.120.0 after pnpm install

Notes for reviewers

  • Confirmed this repo's origin/feat/r2-image-cdn branch does not use a NOISSUE - commit prefix (unlike some other commits in this repo's history), so this PR's commit message matches that branch's own two commits' plain style.
  • Unrelated observation, not touched here: a few MDX files (content/docs/s0-gateway/{index,pinouts,architecture}.mdx) still reference images via the old relative ../images/*.png convention rather than the new /img/* R2 convention — pre-existing on feat/r2-image-cdn, out of scope for this fix.

Add "remote": true to the IMAGES_BUCKET R2 binding in wrangler.jsonc so
`wrangler dev` connects to the real "websites-images" bucket instead of an
empty local simulator -- images published via publish-image.mjs now render
locally without manually seeding local R2 state.

Bump the wrangler devDependency ^4.95.0 -> ^4.120.0: the older version has a
bug where a remote R2 binding throws "SyntaxError: Unexpected end of JSON
input" instead of proxying to R2, which is what made this look broken in
the first place.

Document in scripts/README.md that `wrangler dev` (not `wrangler pages dev`)
is the correct local preview command -- this repo deploys via plain
`wrangler deploy` (Workers + static assets), not Pages, so `pages dev`
silently drops the R2 binding entirely.
@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
hardware-docs ecd130c Commit Preview URL

Branch Preview URL
Aug 07 2026, 04:58 PM

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