From b731b3de73262f8ab9544b1228ea9e693e488b6c Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Tue, 3 Dec 2024 10:51:34 +0000 Subject: [PATCH] fix: make image endpoint highest priority (#12591) * fix: make image endpoint highest priority * Use config for endpoint * Add test --- .changeset/plenty-carrots-nail.md | 5 +++++ packages/astro/src/assets/endpoint/config.ts | 6 +++--- .../src/pages/{index.astro => [...catchall].astro} | 0 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/plenty-carrots-nail.md rename packages/astro/test/fixtures/core-image-ssr/src/pages/{index.astro => [...catchall].astro} (100%) 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