Skip to content

Commit e685c5a

Browse files
SchnizRich-Harris
andauthored
Use general purpose edge functions for vercel-adapter (#4883)
* 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]>
1 parent 6205a11 commit e685c5a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.changeset/rich-singers-taste.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
Use general purpose Edge Functions instead of piggybacking Middleware for Edge Deployment + fix split mode

packages/adapter-vercel/index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ async function v3(builder, external, edge, split) {
329329
})
330330
);
331331

332-
routes.push({ src: pattern, middlewarePath: name });
332+
routes.push({ src: pattern, dest: `/${name}` });
333333
}
334334

335335
const generate_function = edge ? generate_edge_function : generate_serverless_function;
@@ -340,10 +340,19 @@ async function v3(builder, external, edge, split) {
340340
id: route.pattern.toString(), // TODO is `id` necessary?
341341
filter: (other) => route.pattern.toString() === other.pattern.toString(),
342342
complete: async (entry) => {
343-
const src = `${route.pattern
343+
let sliced_pattern = route.pattern
344344
.toString()
345-
.slice(1, -2) // remove leading / and trailing $/
346-
.replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
345+
// remove leading / and trailing $/
346+
.slice(1, -2)
347+
// replace escaped \/ with /
348+
.replace(/\\\//g, '/');
349+
350+
// replace the root route "^/" with "^/?"
351+
if (sliced_pattern === '^/') {
352+
sliced_pattern = '^/?';
353+
}
354+
355+
const src = `${sliced_pattern}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
347356

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

0 commit comments

Comments
 (0)