Skip to content

Enable remote R2 binding so local dev can preview published doc images - #62

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

Enable remote R2 binding so local dev can preview published doc images#62
ianmuchyri wants to merge 1 commit into
mainfrom
fix/docs-local-dev-r2-remote-binding

Conversation

@ianmuchyri

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the equivalent fix already shipped in magistrala-docs: absmach/magistrala-docs#171. Scoped entirely to docs/ — does not touch the Go service.

After publishing a doc image via publish-image.mjs, there was no way to preview it locally:

  • pnpm run dev (plain next dev) has no knowledge of wrangler.jsonc/the Worker, so it always 404s on doc images (expected, unchanged by this PR).
  • wrangler dev runs the real Worker, but its R2 binding defaulted to an empty local simulated bucket, not the real websites-images bucket, so published images still 404'd.
  • The wrangler version previously pinned (^4.95.0) also has a bug where a remote R2 binding throws SyntaxError: Unexpected end of JSON input instead of proxying to R2 at all — confirmed fixed at 4.120.0.

Three changes:

  1. docs/wrangler.jsonc — add "remote": true to the IMAGES_BUCKET r2_buckets binding. This is a local-dev-only setting (per wrangler's own config-schema.json); has no effect on the deployed Worker, since bindings are always real there.
  2. docs/package.json — bump the wrangler devDependency from ^4.95.0 to ^4.120.0 (lockfile updated via pnpm install).
  3. docs/scripts/README.md — new "Previewing images locally" section (right after "Publishing an image", before "Local development"), explaining the pnpm run preview workflow. Also trimmed the now-stale/contradictory paragraph in the existing "Local development" section that told readers to add "remote": true temporarily — it's now on by default, so that section points to the new one instead.

Test plan

  • pnpm run build succeeds
  • wrangler dev startup banner shows env.IMAGES_BUCKET (websites-images) R2 Bucket remote — mode is remote, not local, and no SyntaxError crash
  • Homepage (/) 301s to /docs/atom/, which returns 200
  • Sampled 3 image paths referenced in content/docs/**/*.mdx through the running wrangler dev — all returned 200 with correct image/png content-type and byte sizes matching the originals removed from git in docs: serve doc images from R2 instead of committing them to git #57 (e.g. groups-list-populated.png at exactly 112280 bytes)
  • A genuinely nonexistent image path correctly 404s
  • pnpm run typecheck:worker passes (used by the deploy/upload scripts, confirms the wrangler.jsonc edit didn't break worker typechecking)
  • ./node_modules/.bin/wrangler --version reports 4.120.0

wrangler dev's R2 binding defaulted to an empty local simulator, so
images already published to the shared websites-images bucket via
publish-image.mjs were invisible in local dev (next dev has no
knowledge of wrangler.jsonc at all and always 404s on doc images,
which is separately expected).

- Add "remote": true to the IMAGES_BUCKET binding in wrangler.jsonc.
  Local-dev-only setting per wrangler's own config-schema.json; no
  effect on the deployed Worker.
- Bump wrangler from ^4.95.0 to ^4.120.0. Versions in that range have
  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.
- Document the workflow in scripts/README.md under a new "Previewing
  images locally" section.

Follow-up to the equivalent fix in magistrala-docs:
absmach/magistrala-docs#171
@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
atom-docs f5953b0 Commit Preview URL

Branch Preview URL
Aug 07 2026, 04:56 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