Skip to content

Commit 1974386

Browse files
fix: add redirects for routes containing '__data.json' suffix (#5180)
* 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]>
1 parent 94beed7 commit 1974386

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/tasty-zebras-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-netlify': patch
3+
---
4+
5+
fix: add redirects for routes containing `__data.json` suffix

packages/adapter-netlify/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function generate_edge_functions({ builder }) {
150150
* @param { boolean } params.split
151151
* @param { boolean } params.esm
152152
*/
153-
function generate_lambda_functions({ builder, publish, split, esm }) {
153+
async function generate_lambda_functions({ builder, publish, split, esm }) {
154154
builder.mkdirp('.netlify/functions-internal');
155155

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

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

213213
redirects.push(`${pattern} /.netlify/functions/${name} 200`);
214+
redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
214215
}
215216
};
216217
});

0 commit comments

Comments
 (0)