Skip to content

Commit

Permalink
fix: adapter-netlify redirect for /_data.json (#9006)
Browse files Browse the repository at this point in the history
* fix adapter-netlify leading slash

* shrink code a tad

---------

Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
adamjkb and Rich-Harris authored Feb 12, 2023
1 parent 80b8b92 commit 0f4dd3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-hotels-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

fix: Root route data endpoint redirect when using split routes
11 changes: 6 additions & 5 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { dirname, join, resolve, posix } from 'path';
import { fileURLToPath } from 'url';
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve, posix } from 'node:path';
import { fileURLToPath } from 'node:url';
import esbuild from 'esbuild';
import toml from '@iarna/toml';

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

redirects.push(`${pattern} /.netlify/functions/${name} 200`);
redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
const redirect = `/.netlify/functions/${name} 200`;
redirects.push(`${pattern} ${redirect}`);
redirects.push(`${pattern === '/' ? '' : pattern}/__data.json ${redirect}`);
}
} else {
const manifest = builder.generateManifest({
Expand Down

0 comments on commit 0f4dd3d

Please sign in to comment.