Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(redirects): correctly compute the status code in redirects #9657

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +39 to +40
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were checking the incorrect data

} 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;
}
Comment on lines +481 to +485
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We forgot to find the route in case to is the object

}),
fallbackRoutes: [],
};

Expand Down