Skip to content

IMAGES-2191: improve variant URLs returned by miniflare hosted images mock#13348

Open
mglewis wants to merge 1 commit intocloudflare:mainfrom
mglewis:mattl/IMAGES-2191-better-variant-urls-for-hosted-images
Open

IMAGES-2191: improve variant URLs returned by miniflare hosted images mock#13348
mglewis wants to merge 1 commit intocloudflare:mainfrom
mglewis:mattl/IMAGES-2191-better-variant-urls-for-hosted-images

Conversation

@mglewis
Copy link
Copy Markdown
Member

@mglewis mglewis commented Apr 8, 2026

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 as https://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_DELIVERY and CoreBindings.SERVICE_IMAGES_DELIVERY have been added as entry worker constants.
  • The entry worker routes /cdn-cgi/imagedelivery/ requests to the images service
  • The images service fetch() handler serves raw bytes from KV using sharp.js for content type detection (via /info in the binding)
  • The images service name is passed from the miniflare config assembler to the global services builder, which conditionally binds it to the entry worker
  • Variant URLs are relative paths rather than absolute URLs as I'm not sure how we'd get fully qualified URLs to work with ports

Testing

Three new tests added for the delivery endpoint:

  • Variant URLs use the correct /cdn-cgi/imagedelivery/ format
  • Delivery endpoint serves uploaded image bytes
  • Delivery endpoint returns 404 for non-existent images

Running my local test worker, the images now load:
image

Tests

  • Tests included/updated
  • Automated tests not possible - manual testing has been completed as follows:
  • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this feature hasn't been released yet
image
Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 8, 2026

🦋 Changeset detected

Latest 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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 8, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13348

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13348

miniflare

npm i https://pkg.pr.new/miniflare@13348

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13348

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13348

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13348

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13348

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13348

wrangler

npm i https://pkg.pr.new/wrangler@13348

commit: 4e488eb

@mglewis mglewis force-pushed the mattl/IMAGES-2191-better-variant-urls-for-hosted-images branch from 994a828 to 8ce4647 Compare April 8, 2026 12:20
@mglewis mglewis marked this pull request as ready for review April 8, 2026 12:21
@mglewis mglewis requested a review from workers-devprod as a code owner April 8, 2026 12:21
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team April 8, 2026 12:21
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/miniflare/src/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/core/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/constants.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/core/entry.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/images/images.worker.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/images/index.spec.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

@mglewis mglewis force-pushed the mattl/IMAGES-2191-better-variant-urls-for-hosted-images branch 3 times, most recently from d5dc7d1 to 4a98618 Compare April 10, 2026 10:56
@mglewis mglewis force-pushed the mattl/IMAGES-2191-better-variant-urls-for-hosted-images branch from 4a98618 to 4e488eb Compare April 10, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants