summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/clever-vans-flash.md5
-rw-r--r--packages/astro/src/vite-plugin-astro-server/route.ts8
-rw-r--r--packages/astro/test/i18n-routing-manual.test.js4
3 files changed, 13 insertions, 4 deletions
diff --git a/.changeset/clever-vans-flash.md b/.changeset/clever-vans-flash.md
new file mode 100644
index 000000000..3f616316a
--- /dev/null
+++ b/.changeset/clever-vans-flash.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes an issue where the middleware wasn't called when a project uses `404.astro`.
diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts
index aa70d5324..d6084dbdd 100644
--- a/packages/astro/src/vite-plugin-astro-server/route.ts
+++ b/packages/astro/src/vite-plugin-astro-server/route.ts
@@ -1,6 +1,7 @@
import type http from 'node:http';
import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro.js';
import {
+ DEFAULT_404_COMPONENT,
REROUTE_DIRECTIVE_HEADER,
REWRITE_DIRECTIVE_HEADER_KEY,
clientLocalsSymbol,
@@ -192,13 +193,16 @@ export async function handleRoute({
mod = preloadedComponent;
- const isPrerendered404 = matchedRoute.route.route === '/404' && matchedRoute.route.prerender;
+ const isDefaultPrerendered404 =
+ matchedRoute.route.route === '/404' &&
+ matchedRoute.route.prerender &&
+ matchedRoute.route.component === DEFAULT_404_COMPONENT;
renderContext = RenderContext.create({
locals,
pipeline,
pathname,
- middleware: isPrerendered404 ? undefined : middleware,
+ middleware: isDefaultPrerendered404 ? undefined : middleware,
request,
routeData: route,
});
diff --git a/packages/astro/test/i18n-routing-manual.test.js b/packages/astro/test/i18n-routing-manual.test.js
index d0de75fe8..3a9efe643 100644
--- a/packages/astro/test/i18n-routing-manual.test.js
+++ b/packages/astro/test/i18n-routing-manual.test.js
@@ -53,9 +53,9 @@ describe('Dev server manual routing', () => {
assert.equal(text.includes('Hola.'), true);
});
- it('should not redirect prerendered 404 routes in dev', async () => {
+ it('should call the middleware for 404.astro pages', async () => {
const response = await fixture.fetch('/redirect-me');
- assert.equal(response.status, 404);
+ assert.equal(response.status, 200);
});
});