Skip to content

Commit 0f4dd3d

Browse files
adamjkbRich-Harris
andauthored
fix: adapter-netlify redirect for /_data.json (#9006)
* fix adapter-netlify leading slash * shrink code a tad --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 80b8b92 commit 0f4dd3d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.changeset/rotten-hotels-allow.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: Root route data endpoint redirect when using split routes

packages/adapter-netlify/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
2-
import { dirname, join, resolve, posix } from 'path';
3-
import { fileURLToPath } from 'url';
1+
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
2+
import { dirname, join, resolve, posix } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
44
import esbuild from 'esbuild';
55
import toml from '@iarna/toml';
66

@@ -231,8 +231,9 @@ async function generate_lambda_functions({ builder, publish, split }) {
231231
writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
232232
writeFileSync(`.netlify/functions-internal/${name}.json`, fn_config);
233233

234-
redirects.push(`${pattern} /.netlify/functions/${name} 200`);
235-
redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
234+
const redirect = `/.netlify/functions/${name} 200`;
235+
redirects.push(`${pattern} ${redirect}`);
236+
redirects.push(`${pattern === '/' ? '' : pattern}/__data.json ${redirect}`);
236237
}
237238
} else {
238239
const manifest = builder.generateManifest({

0 commit comments

Comments
 (0)