mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
fix(routing): call middleware when rendering 404.astro
(#12034)
This commit is contained in:
parent
fc3e40ecde
commit
5b3ddfadcb
3 changed files with 13 additions and 4 deletions
5
.changeset/clever-vans-flash.md
Normal file
5
.changeset/clever-vans-flash.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue where the middleware wasn't called when a project uses `404.astro`.
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue