Skip to content

fix: cloudflare passthrough image service endpoint#15794

Merged
Princesseuh merged 3 commits intomainfrom
fix/cloudflare-passthrough-endpoint
Mar 11, 2026
Merged

fix: cloudflare passthrough image service endpoint#15794
Princesseuh merged 3 commits intomainfrom
fix/cloudflare-passthrough-endpoint

Conversation

@OliverSpeir
Copy link
Contributor

@OliverSpeir OliverSpeir commented Mar 7, 2026

Changes

Adds a Cloudflare-specific /_image passthrough endpoint that serves local assets via env.ASSETS and proxies remote images via fetch.

When using imageService: 'passthrough' or imageService: 'compile' currently, the /_image endpoint falls back to Astro's generic endpoint which loads local assets by fetching the same origin.

In Cloudflare Workers, without the global_fetch_strictly_public compatibility flag (not included in the default generated wrangler config), same-origin fetch are routed back through the Worker's own fetch handler rather than the CDN. Since the Worker doesn't handle /_astro/ paths, the request returns 404.

This bypasses HTTP routing entirely (for local assets) and works regardless of compatibility flags.

Testing

manually with pnpm preview

Docs

n/a

@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2026

🦋 Changeset detected

Latest commit: 89730c2

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

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Mar 7, 2026
@ematipico
Copy link
Member

ematipico commented Mar 9, 2026

What are we fixing @OliverSpeir ? It's notclear from the description. And since we don't have an issue, we should explain it.

@jahndan
Copy link

jahndan commented Mar 9, 2026

@ematipico here's my message about it from discord as context

when using the cloudflare adapter, I'm getting 404s for images in this specific situation:

  • Image component uses an image imported from src

I made a page that uses the Image component and img tags for both local (src) and remote (public) images, and only the case mentioned above has the 404

GET / 200 OK (5ms)
GET /_astro/raytraced.BfEvAycb.png 200 OK (4ms)
GET /raytraced.png 200 OK (9ms)
GET /_image 404 Not Found (5ms)

(outside of the repro example this also happens for images in a content collection)

it doesn't happen in the dev server, only in the build + preview (and when deployed) - i made a minimal repro at https://github.com/jahndan/astro-v6-feedback

if needed i can file an issue, but i dont know much about the process

I hadn't filed an issue because I wasn't familiar with the process.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Princesseuh Princesseuh merged commit d1ac58e into main Mar 11, 2026
20 of 21 checks passed
@Princesseuh Princesseuh deleted the fix/cloudflare-passthrough-endpoint branch March 11, 2026 16:44
@astrobot-houston astrobot-houston mentioned this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants