Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: append prerendered redirects to _redirects file #12199

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Generate static _routes in Cloudflare adapter
  • Loading branch information
Zhincore committed May 8, 2024
commit f2c0dd074a3aa401573dfd295d9c27be4a4f022b
5 changes: 5 additions & 0 deletions .changeset/ten-shirts-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-cloudflare": minor
---

feat: Generate static \_redirects for Cloudflare Pages
10 changes: 10 additions & 0 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default function (options = {}) {

writeFileSync(`${dest}/_headers`, generate_headers(builder.getAppPath()), { flag: 'a' });

writeFileSync(`${dest}/_redirects`, generate_redirects(builder), { flag: 'a' });

builder.copy(`${files}/worker.js`, `${tmp}/_worker.js`, {
replace: {
SERVER: `${relativePath}/index.js`,
Expand Down Expand Up @@ -239,3 +241,11 @@ function generate_headers(app_dir) {
# === END AUTOGENERATED SVELTE IMMUTABLE HEADERS ===
`.trimEnd();
}

/** @param {import('@sveltejs/kit').Builder} builder */
function generate_redirects(builder) {
return Array.from(
builder.prerendered.redirects.entries(),
([path, redirect]) => `${path} ${redirect.location} ${redirect.status}`
).join('\n');
}
Loading