mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Fix redirect in SSR (Node and dynamic) (#7856)
This commit is contained in:
parent
98ca04f915
commit
861f10eafd
4 changed files with 11 additions and 2 deletions
5
.changeset/green-berries-flow.md
Normal file
5
.changeset/green-berries-flow.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Properly serialize redirect config for SSR
|
|
@ -1962,9 +1962,10 @@ export type RedirectRouteData = RouteData & {
|
|||
redirect: string;
|
||||
};
|
||||
|
||||
export type SerializedRouteData = Omit<RouteData, 'generate' | 'pattern'> & {
|
||||
export type SerializedRouteData = Omit<RouteData, 'generate' | 'pattern' | 'redirectRoute'> & {
|
||||
generate: undefined;
|
||||
pattern: string;
|
||||
redirectRoute: SerializedRouteData | undefined;
|
||||
_meta: {
|
||||
trailingSlash: AstroConfig['trailingSlash'];
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@ export function serializeRouteData(
|
|||
...routeData,
|
||||
generate: undefined,
|
||||
pattern: routeData.pattern.source,
|
||||
redirectRoute: routeData.redirectRoute ? serializeRouteData(routeData.redirectRoute, trailingSlash) : undefined,
|
||||
_meta: { trailingSlash },
|
||||
};
|
||||
}
|
||||
|
@ -25,5 +26,7 @@ export function deserializeRouteData(rawRouteData: SerializedRouteData): RouteDa
|
|||
pathname: rawRouteData.pathname || undefined,
|
||||
segments: rawRouteData.segments,
|
||||
prerender: rawRouteData.prerender,
|
||||
redirect: rawRouteData.redirect,
|
||||
redirectRoute: rawRouteData.redirectRoute ? deserializeRouteData(rawRouteData.redirectRoute) : undefined,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Astro.redirect', () => {
|
|||
const request = new Request('http://example.com/api/redirect');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(301);
|
||||
expect(response.headers.get('Location')).to.equal('/');
|
||||
expect(response.headers.get('Location')).to.equal('/test');
|
||||
});
|
||||
|
||||
it('Uses 308 for non-GET methods', async () => {
|
||||
|
|
Loading…
Reference in a new issue