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:
parent
5afc8f2088
commit
9ba3e2605d
3 changed files with 15 additions and 3 deletions
5
.changeset/fifty-buttons-clean.md
Normal file
5
.changeset/fifty-buttons-clean.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes an issue where returning redirect responses resulted in missing files with certain adapters.
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue