diff options
author | 2022-05-11 17:13:23 +0200 | |
---|---|---|
committer | 2022-05-11 09:13:23 -0600 | |
commit | 352fc3166fe3b3d3da3feff621394b20eacb9cc3 (patch) | |
tree | 2d0f1a2a142b35c03a72d20d5cd873bf38ae4e23 /packages/integrations/netlify/src/integration-functions.ts | |
parent | 9c98ba81e1cde14a3772cbc9ee020956dae996e8 (diff) | |
download | astro-352fc3166fe3b3d3da3feff621394b20eacb9cc3.tar.gz astro-352fc3166fe3b3d3da3feff621394b20eacb9cc3.tar.zst astro-352fc3166fe3b3d3da3feff621394b20eacb9cc3.zip |
Fix/netlify edge redirects (#3342)
* fix: create redirects file for netlify edge adapter
* chore: changeset
* chore: distinguish between edge/regular
Diffstat (limited to 'packages/integrations/netlify/src/integration-functions.ts')
-rw-r--r-- | packages/integrations/netlify/src/integration-functions.ts | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/packages/integrations/netlify/src/integration-functions.ts b/packages/integrations/netlify/src/integration-functions.ts index 2720eb591..81cb7e9fd 100644 --- a/packages/integrations/netlify/src/integration-functions.ts +++ b/packages/integrations/netlify/src/integration-functions.ts @@ -1,5 +1,5 @@ import type { AstroAdapter, AstroIntegration, AstroConfig } from 'astro'; -import fs from 'fs'; +import { createRedirects } from './shared.js'; export function getAdapter(): AstroAdapter { return { @@ -37,26 +37,7 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat buildConfig.server = new URL('./functions/', _config.outDir); }, 'astro:build:done': async ({ routes, dir }) => { - const _redirectsURL = new URL('./_redirects', dir); - - // Create the redirects file that is used for routing. - let _redirects = ''; - for (const route of routes) { - if (route.pathname) { - _redirects += ` -${route.pathname} /.netlify/functions/${entryFile} 200`; - } else { - const pattern = - '/' + route.segments.map(([part]) => (part.dynamic ? '*' : part.content)).join('/'); - _redirects += ` -${pattern} /.netlify/functions/${entryFile} 200`; - } - } - - // 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'); + await createRedirects(routes, dir, entryFile, false); }, }, }; |