diff --git a/.changeset/lemon-elephants-sell.md b/.changeset/lemon-elephants-sell.md new file mode 100644 index 000000000000..5f68dd2b5067 --- /dev/null +++ b/.changeset/lemon-elephants-sell.md @@ -0,0 +1,5 @@ +--- +'@astrojs/netlify': patch +--- + +Make Netlify adapter actually append redirects diff --git a/packages/integrations/netlify/src/index.ts b/packages/integrations/netlify/src/index.ts index 60aad4b79b13..c473de67ae63 100644 --- a/packages/integrations/netlify/src/index.ts +++ b/packages/integrations/netlify/src/index.ts @@ -53,11 +53,10 @@ ${pattern} /.netlify/functions/${entryFile} 200`; } } - if (fs.existsSync(_redirects)) { - await fs.promises.appendFile(_redirectsURL, _redirects, 'utf-8'); - } else { - await fs.promises.writeFile(_redirectsURL, _redirects, 'utf-8'); - } + // Always use appendFile() because the redirects file could already exist, + // e.g. due to a `/public/_redirects` file that got copied to the output dir. + // If the file does not exist yet, appendFile() automatically creates it. + await fs.promises.appendFile(_redirectsURL, _redirects, 'utf-8'); }, }, };