IMAGES-2191: improve variant URLs returned by miniflare hosted images mock#13348
Open
mglewis wants to merge 1 commit intocloudflare:mainfrom
Open
IMAGES-2191: improve variant URLs returned by miniflare hosted images mock#13348mglewis wants to merge 1 commit intocloudflare:mainfrom
mglewis wants to merge 1 commit intocloudflare:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 4e488eb 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
wrangler
commit: |
994a828 to
8ce4647
Compare
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
d5dc7d1 to
4a98618
Compare
4a98618 to
4e488eb
Compare
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.
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 relative paths pointing to this endpoint (/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 local explorer UI, 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)Testing
Three new tests added for the delivery endpoint:
/cdn-cgi/imagedelivery/formatRunning my local test worker, the images now load:

Tests