Skip to content

Commit

Permalink
fix(redirects): correctly compute the status code in redirects (#9657)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jan 10, 2024
1 parent a1b56ee commit a4f90d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-seas-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes a bug where the custom status code wasn't correctly computed in the dev server
4 changes: 2 additions & 2 deletions packages/astro/src/core/redirects/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function redirectRouteGenerate(redirectRoute: RouteData, data: Params): s

export function redirectRouteStatus(redirectRoute: RouteData, method = 'GET'): ValidRedirectStatus {
const routeData = redirectRoute.redirectRoute;
if (typeof routeData?.redirect === 'object') {
return routeData.redirect.status;
if (routeData && typeof redirectRoute.redirect === 'object') {
return redirectRoute.redirect.status;
} else if (method !== 'GET') {
return 308;
}
Expand Down
8 changes: 7 additions & 1 deletion packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,13 @@ export function createRouteManifest(
pathname: pathname || void 0,
prerender: false,
redirect: to,
redirectRoute: routes.find((r) => r.route === to),
redirectRoute: routes.find((r) => {
if (typeof to === 'object') {
return r.route === to.destination;
} else {
return r.route === to;
}
}),
fallbackRoutes: [],
};

Expand Down

0 comments on commit a4f90d9

Please sign in to comment.