0
Fork 0
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:
Matthew Phillips 2023-07-28 12:00:26 -04:00 committed by GitHub
parent 98ca04f915
commit 861f10eafd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Properly serialize redirect config for SSR

View file

@ -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'];
};

View file

@ -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,
};
}

View file

@ -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 () => {