Skip to content

Commit

Permalink
append function redirects after copying existing redirects - fixes #4722
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 12, 2022
1 parent c8e9822 commit b270759
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-books-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

Copy existing \_redirects file before appending function redirects
26 changes: 13 additions & 13 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {

builder.log.minor(`Publishing to "${publish}"`);

builder.log.minor('Copying assets...');
builder.writeStatic(publish);
builder.writeClient(publish);
builder.writePrerendered(publish);

builder.log.minor('Writing custom headers...');
const headers_file = join(publish, '_headers');
builder.copy('_headers', headers_file);
appendFileSync(
headers_file,
`\n\n/${builder.config.kit.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`
);

// for esbuild, use ESM
// for zip-it-and-ship-it, use CJS until https://github.com/netlify/zip-it-and-ship-it/issues/750
const esm = netlify_config?.functions?.node_bundler === 'esbuild';
Expand All @@ -67,19 +80,6 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
} else {
await generate_lambda_functions({ builder, esm, split, publish });
}

builder.log.minor('Copying assets...');
builder.writeStatic(publish);
builder.writeClient(publish);
builder.writePrerendered(publish);

builder.log.minor('Writing custom headers...');
const headers_file = join(publish, '_headers');
builder.copy('_headers', headers_file);
appendFileSync(
headers_file,
`\n\n/${builder.config.kit.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`
);
}
};
}
Expand Down

0 comments on commit b270759

Please sign in to comment.