IMAGES-2191: improve variant URLs returned by miniflare hosted images mock#13348
Conversation
🦋 Changeset detectedLatest commit: 4a1f61c The changes in this PR will be included in the next version bump. 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 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
994a828 to
8ce4647
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
4a98618 to
4e488eb
Compare
4e488eb to
1da4359
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
1da4359 to
d2be25f
Compare
|
Could you update this to follow the host detection logic added in #13234? Perhaps it would be simpler for that to merge first and then build on top of it. |
sure thing 👍 I'll wait for it to merge |
ddf8969 to
8fb009f
Compare
This has now been updated |
penalosa
left a comment
There was a problem hiding this comment.
This is looking good! A few small comments and then we can get it in
|
Codeowners approval required for this PR:
Show detailed file reviewers |
8fb009f to
6ca0346
Compare
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
6ca0346 to
7e305cb
Compare
7e305cb to
4a1f61c
Compare
The miniflare hosted images mock currently returns bare variant names (e.g.
"public") in the variants field of ImageMetadata. In production, this field contains full delivery URLs such ashttps://imagedelivery.net/<account_hash>/<image_id>/public. These bare names are not usable in an<img src=...>, resulting in variant URLs failing to display when running in local mode.This PR introduces a local image delivery endpoint at
/cdn-cgi/imagedelivery/<image_id>/<variant>that serves image bytes directly from the existing miniflare KV store. The variants field now returns absolute URLs pointing to this endpoint (<hostname>/cdn-cgi/imagedelivery/<image>/public), making them functional in a browser during local development.Implementation Details
The approach follows the same pattern used by the Stream binding (#13234), with a reserved
/cdn-cgi/path intercepted by the entry worker and forwarded to the images service.CorePaths.IMAGE_DELIVERYandCoreBindings.SERVICE_IMAGES_DELIVERYhave been added as entry worker constants./cdn-cgi/imagedelivery/requests to the images servicefetch()handler serves raw bytes from KV using sharp.js for content type detection (via/infoin the binding)/core/public-urlloopback route introduced in [Stream] Add support for serving videos locally + watermark/caption upload support #13234, so they always reflect the current MiniflarepublicUrl(tolerating restarts). This boilerplate previously lived in a stream specific nook of the codebase, but has been relocated to a helper inminiflare:shared.Testing
Three new tests added for the delivery endpoint:
/cdn-cgi/imagedelivery/formatRunning my local test worker, the images now load:

Tests