Skip to content

Commit

Permalink
Append of the file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Mar 25, 2022
1 parent 451c166 commit e187466
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/integrations/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
buildConfig.server = new URL('./functions/', _config.dist);
},
'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) {
Expand All @@ -45,8 +47,12 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
${route.pathname} /.netlify/functions/${entryFile} 200`
}
}
const _redirectsURL = new URL('./_redirects', dir);
await fs.promises.writeFile(_redirectsURL, _redirects, 'utf-8');

if(fs.existsSync(_redirects)) {
await fs.promises.appendFile(_redirectsURL, _redirects, 'utf-8');
} else {
await fs.promises.writeFile(_redirectsURL, _redirects, 'utf-8');
}
}
},
};
Expand Down

0 comments on commit e187466

Please sign in to comment.