Fix local dev R2 binding so published images preview correctly - #135
Open
ianmuchyri wants to merge 1 commit into
Open
ianmuchyri wants to merge 1 commit into
ianmuchyri wants to merge 1 commit into
Conversation
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.
Deploying with
|
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the equivalent fix in magistrala-docs: absmach/magistrala-docs#171
Previously, once an image was published to the shared
websites-imagesR2 bucket viascripts/publish-image.mjs, there was no way to actually preview it locally:pnpm run dev(plainnext dev) has zero knowledge ofwrangler.jsonc/ the Worker, so it always 404s on doc images (expected, not fixed here).wrangler devruns the real Worker, but its R2 binding defaulted to an empty local simulated bucket, not the real one, so published images still 404'd.wranglerversion pinned inpackage.json(^4.81.1) falls in a range with a real bug: a remote R2 binding throwsSyntaxError: Unexpected end of JSON inputinstead of proxying to R2 at all. Confirmed fixed at wrangler4.120.0.Three changes:
wrangler.jsonc: add"remote": trueto theIMAGES_BUCKETR2 binding, sowrangler devproxies to the real bucket instead of an empty local simulator. Confirmed via wrangler's ownconfig-schema.jsonthat this field is local-dev-only and has no effect on the deployed Worker.package.json: bumpwranglerdevDependency from^4.81.1to^4.120.0, withpnpm-lock.yamlupdated accordingly (pnpm installalso added twominimumReleaseAgeExcludeentries topnpm-workspace.yamlforwrangler@4.120.0andminiflare@5.20260801.1-alpha, a pnpm supply-chain-age guard needed to resolve those versions).scripts/README.md: new "Previewing images locally" section (placed after "Publishing an image", before "Bulk-uploading via the R2 dashboard") documenting thepnpm run build && npx wrangler devworkflow, the"remote": truebinding, and the wrangler version requirement.Test plan
pnpm install— lockfile updated,./node_modules/.bin/wrangler --versionreports4.120.0pnpm run types:check— passes (this repo's script also runswrangler types)pnpm run build— succeeds, produces./outnpx wrangler dev— startup banner showsenv.IMAGES_BUCKET (websites-images) R2 Bucket remote(mode = remote, not local); noSyntaxErrorcrash/redirects 301 to/docs/cocos-ai/, which returns 200 — that's this site's existing basePath redirect, unrelated to this change)/docs/cocos-ai/img/agent/overview.png) through the runningwrangler dev— after the "Establishing remote connection" phase settled, it returned the actual PNG bytes from the real bucket