-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: update Cloudflare adapter's default image service #15435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Princesseuh
merged 21 commits into
withastro:main
from
rururux:cloudflare-image-component
Feb 24, 2026
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b305c97
fix: use `@astrojs/cloudflare/image-endpoint` for Cloudflare dev server
rururux 015b212
Change the entrypoint configuration method
rururux 26a8abd
Merge branch 'main' into cloudflare-image-component
rururux aabfd32
Merge branch 'fix/hahahah-picomatch-cjs' into cloudflare-image-component
Princesseuh 31e58e9
fix(assets): precompile dev deny glob pattern to avoid CJS deps
Princesseuh 2d9a5ec
feat: change default to bindings
Princesseuh 9152bfd
fix: explain comment
Princesseuh 24d2e58
Merge branch 'main' into cloudflare-image-component
Princesseuh 04380dc
fix: use generic endpoint in passthrough
Princesseuh f518c40
chore: lockfile
Princesseuh b4dd89c
Merge branch 'main' into cloudflare-image-component
Princesseuh 442d013
chore: changeset
Princesseuh 943c250
Merge remote-tracking branch 'origin/main' into cloudflare-image-comp…
OliverSpeir 260c122
feat: cache cloudflare-binding transforms
OliverSpeir 66a44d7
feat: fix/improve compile
OliverSpeir a829eb6
Merge branch 'main' into cloudflare-image-component
Princesseuh f0a8d3f
remove `debug` package
rururux 6d1c5bd
fix changesets
OliverSpeir d62a625
Update cloudflare-image-service-object.md
OliverSpeir ee449bd
Update cloudflare-image-component.md
OliverSpeir 233774b
Apply suggestion from @sarah11918
Princesseuh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
150 changes: 108 additions & 42 deletions
150
packages/integrations/cloudflare/test/compile-image-service.test.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,129 @@ | ||
| import * as assert from 'node:assert/strict'; | ||
| import { after, before, describe, it } from 'node:test'; | ||
| import * as cheerio from 'cheerio'; | ||
| import { loadFixture } from './_test-utils.js'; | ||
|
|
||
| describe('CompileImageService', () => { | ||
| let fixture; | ||
| let previewServer; | ||
|
|
||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/compile-image-service/', | ||
| }); | ||
| await fixture.build(); | ||
| previewServer = await fixture.preview(); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await previewServer.stop(); | ||
| }); | ||
| describe('dev', () => { | ||
| let devServer; | ||
|
|
||
| it('forbids http://', async () => { | ||
| const res = await fixture.fetch('/_image?href=http://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
| before(async () => { | ||
| devServer = await fixture.startDevServer(); | ||
| }); | ||
|
|
||
| it('forbids https://', async () => { | ||
| const res = await fixture.fetch('/_image?href=https://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
| after(async () => { | ||
| await devServer.stop(); | ||
| }); | ||
|
|
||
| it('forbids //', async () => { | ||
| const res = await fixture.fetch('/_image?href=//placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Blocked'); | ||
| assert.equal(status, 403); | ||
| }); | ||
| it('forbids http://', async () => { | ||
| const res = await fixture.fetch('/_image?href=http://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('allows trusted with redirect', async () => { | ||
| const res = await fixture.fetch( | ||
| '/_image?href=https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp', | ||
| { redirect: 'manual' }, | ||
| ); | ||
| const header = res.headers.get('location'); | ||
| const status = res.status; | ||
| assert.equal(header, 'https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp'); | ||
| assert.equal(status, 302); | ||
| it('forbids https://', async () => { | ||
| const res = await fixture.fetch('/_image?href=https://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('forbids //', async () => { | ||
| const res = await fixture.fetch('/_image?href=//placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Blocked'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('allows trusted with redirect', async () => { | ||
| const res = await fixture.fetch( | ||
| '/_image?href=https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp', | ||
| { redirect: 'manual' }, | ||
| ); | ||
| const header = res.headers.get('location'); | ||
| const status = res.status; | ||
| assert.equal(header, 'https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp'); | ||
| assert.equal(status, 302); | ||
| }); | ||
|
|
||
| // On the dev server, the URL for local images includes an absolute path, | ||
| // making it difficult to specify statically. Thus, we retrieve it dynamically from the HTML. | ||
| it('allows local', async () => { | ||
| const html = await fixture.fetch('/blog/post').then((res) => res.text()); | ||
| const $ = cheerio.load(html); | ||
| const res = await fixture.fetch($('img').attr('src')); | ||
| const blob = await res.blob(); | ||
| const status = res.status; | ||
| assert.equal(blob.type, 'image/jpeg'); | ||
| assert.equal(status, 200); | ||
| }); | ||
| }); | ||
|
|
||
| it('allows local', async () => { | ||
| const res = await fixture.fetch('/_image?href=/_astro/placeholder.gLBdjEDe.jpg'); | ||
| const blob = await res.blob(); | ||
| const status = res.status; | ||
| assert.equal(blob.type, 'image/jpeg'); | ||
| assert.equal(status, 200); | ||
| describe('preview', () => { | ||
| let previewServer; | ||
|
|
||
| before(async () => { | ||
| await fixture.build(); | ||
| previewServer = await fixture.preview(); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await previewServer.stop(); | ||
| }); | ||
|
|
||
| it('forbids http://', async () => { | ||
| const res = await fixture.fetch('/_image?href=http://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('forbids https://', async () => { | ||
| const res = await fixture.fetch('/_image?href=https://placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Forbidden'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('forbids //', async () => { | ||
| const res = await fixture.fetch('/_image?href=//placehold.co/600x400'); | ||
| const html = await res.text(); | ||
| const status = res.status; | ||
| assert.equal(html, 'Blocked'); | ||
| assert.equal(status, 403); | ||
| }); | ||
|
|
||
| it('allows trusted with redirect', async () => { | ||
| const res = await fixture.fetch( | ||
| '/_image?href=https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp', | ||
| { redirect: 'manual' }, | ||
| ); | ||
| const header = res.headers.get('location'); | ||
| const status = res.status; | ||
| assert.equal(header, 'https://astro.build/_astro/HeroBackground.B0iWl89K_2hpsgp.webp'); | ||
| assert.equal(status, 302); | ||
| }); | ||
|
|
||
| it('allows local', async () => { | ||
| const res = await fixture.fetch('/_image?href=/_astro/placeholder.gLBdjEDe.jpg'); | ||
| const blob = await res.blob(); | ||
| const status = res.status; | ||
| assert.equal(blob.type, 'image/jpeg'); | ||
| assert.equal(status, 200); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.