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(build): skip only the configured redirects #10279

Merged
merged 3 commits into from
Mar 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-buttons-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes an issue where returning redirect responses resulted in missing files with certain adapters.
5 changes: 3 additions & 2 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,9 @@ async function generatePath(
}

if (response.status >= 300 && response.status < 400) {
// If redirects is set to false, don't output the HTML
if (!config.build.redirects) {
// Adapters may handle redirects themselves, turning off Astro's redirect handling using `config.build.redirects` in the process.
// In that case, we skip rendering static files for the redirect routes.
if (routeIsRedirect(route) && !config.build.redirects) {
return;
}
const locationSite = getRedirectLocationOrThrow(response.headers);
Expand Down
8 changes: 7 additions & 1 deletion packages/astro/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,18 @@ describe('Astro.redirect', () => {
await fixture.build();
});

it('Does not output redirect HTML', async () => {
it('Does not output redirect HTML for redirect routes', async () => {
let oneHtml = undefined;
try {
oneHtml = await fixture.readFile('/one/index.html');
} catch {}
assert.equal(oneHtml, undefined);
});

it('Outputs redirect HTML for user routes that return a redirect response', async () => {
let secretHtml = await fixture.readFile('/secret/index.html');
assert.equal(secretHtml.includes("Redirecting from <code>/secret/</code>"), true);
assert.equal(secretHtml.includes("to <code>/login</code>"), true);
});
});
});