Skip to content

Commit

Permalink
fix: add redirects for routes containing '__data.json' suffix (#5180)
Browse files Browse the repository at this point in the history
* fix: add redirect for routes containing __data.json suffix

* fix: await for builder.createEntries to complete before writing redirects file

* chore: add changeset entry

* Update tasty-zebras-guess.md

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
ericapisani and Rich-Harris authored Jun 22, 2022
1 parent 94beed7 commit 1974386
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-zebras-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

fix: add redirects for routes containing `__data.json` suffix
5 changes: 3 additions & 2 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async function generate_edge_functions({ builder }) {
* @param { boolean } params.split
* @param { boolean } params.esm
*/
function generate_lambda_functions({ builder, publish, split, esm }) {
async function generate_lambda_functions({ builder, publish, split, esm }) {
builder.mkdirp('.netlify/functions-internal');

/** @type {string[]} */
Expand All @@ -177,7 +177,7 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
if (split) {
builder.log.minor('Generating serverless functions...');

builder.createEntries((route) => {
await builder.createEntries((route) => {
const parts = [];
// Netlify's syntax uses '*' and ':param' as "splats" and "placeholders"
// https://docs.netlify.com/routing/redirects/redirect-options/#splats
Expand Down Expand Up @@ -211,6 +211,7 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
writeFileSync(`.netlify/functions-internal/${name}.js`, fn);

redirects.push(`${pattern} /.netlify/functions/${name} 200`);
redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
}
};
});
Expand Down

0 comments on commit 1974386

Please sign in to comment.