0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

fix(build): skip only the configured redirects (#10279)

* fix(build): allow redirect responses to output files

* add changeset

* add test
This commit is contained in:
Arsh 2024-03-04 17:14:34 +05:30 committed by GitHub
parent 5afc8f2088
commit 9ba3e2605d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixes an issue where returning redirect responses resulted in missing files with certain adapters.

View file

@ -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);

View file

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