diff --git a/.changeset/fifty-buttons-clean.md b/.changeset/fifty-buttons-clean.md new file mode 100644 index 0000000000..335ea114ef --- /dev/null +++ b/.changeset/fifty-buttons-clean.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where returning redirect responses resulted in missing files with certain adapters. diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 0b8594bb96..6a9f0610c0 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -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); diff --git a/packages/astro/test/redirects.test.js b/packages/astro/test/redirects.test.js index 443b820734..9775cd025d 100644 --- a/packages/astro/test/redirects.test.js +++ b/packages/astro/test/redirects.test.js @@ -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 /secret/"), true); + assert.equal(secretHtml.includes("to /login"), true); + }); }); });