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

Use general purpose edge functions for vercel-adapter #4883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/rich-singers-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Use general purpose Edge Functions instead of piggybacking Middleware for Edge Deployment + fix split mode
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 13 additions & 4 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async function v3(builder, external, edge, split) {
})
);

routes.push({ src: pattern, middlewarePath: name });
routes.push({ src: pattern, dest: `/${name}` });
}

const generate_function = edge ? generate_edge_function : generate_serverless_function;
Expand All @@ -340,10 +340,19 @@ async function v3(builder, external, edge, split) {
id: route.pattern.toString(), // TODO is `id` necessary?
filter: (other) => route.pattern.toString() === other.pattern.toString(),
complete: async (entry) => {
const src = `${route.pattern
let sliced_pattern = route.pattern
.toString()
.slice(1, -2) // remove leading / and trailing $/
.replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
// remove leading / and trailing $/
.slice(1, -2)
// replace escaped \/ with /
.replace(/\\\//g, '/');

// replace the root route "^/" with "^/?"
if (sliced_pattern === '^/') {
sliced_pattern = '^/?';
}

const src = `${sliced_pattern}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes

await generate_function(route.id || 'index', src, entry.generateManifest);
}
Expand Down