diff --git a/.changeset/plenty-carrots-nail.md b/.changeset/plenty-carrots-nail.md new file mode 100644 index 000000000000..706366b40cce --- /dev/null +++ b/.changeset/plenty-carrots-nail.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug where a catchall route would match an image endpoint request diff --git a/packages/astro/src/assets/endpoint/config.ts b/packages/astro/src/assets/endpoint/config.ts index b9309d446997..cce5cde5fc37 100644 --- a/packages/astro/src/assets/endpoint/config.ts +++ b/packages/astro/src/assets/endpoint/config.ts @@ -13,7 +13,7 @@ export function injectImageEndpoint( mode: 'dev' | 'build', cwd?: string, ) { - manifest.routes.push(getImageEndpointData(settings, mode, cwd)); + manifest.routes.unshift(getImageEndpointData(settings, mode, cwd)); } export function ensureImageEndpointRoute( @@ -22,8 +22,8 @@ export function ensureImageEndpointRoute( mode: 'dev' | 'build', cwd?: string, ) { - if (!manifest.routes.some((route) => route.route === '/_image')) { - manifest.routes.push(getImageEndpointData(settings, mode, cwd)); + if (!manifest.routes.some((route) => route.route === settings.config.image.endpoint.route)) { + manifest.routes.unshift(getImageEndpointData(settings, mode, cwd)); } } diff --git a/packages/astro/test/fixtures/core-image-ssr/src/pages/index.astro b/packages/astro/test/fixtures/core-image-ssr/src/pages/[...catchall].astro similarity index 100% rename from packages/astro/test/fixtures/core-image-ssr/src/pages/index.astro rename to packages/astro/test/fixtures/core-image-ssr/src/pages/[...catchall].astro