Skip to content

Commit

Permalink
Use general purpose edge functions for vercel-adapter (#4883)
Browse files Browse the repository at this point in the history
* Use `dest` instead of `middlewarePath`

This will use general purpose edge functions instead of our Middleware
infrastructure. This will support Cache-Control and also streamlines the
routing.

* Fix routing in `split: true`

* Add changeset

* Update packages/adapter-vercel/index.js

* Update packages/adapter-vercel/index.js

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
Schniz and Rich-Harris authored May 16, 2022
1 parent 6205a11 commit e685c5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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
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

0 comments on commit e685c5a

Please sign in to comment.