From dfbc7079081d3346713cb536358a3854362a2c95 Mon Sep 17 00:00:00 2001 From: Geoffrey Casper Date: Thu, 7 Dec 2023 08:43:47 -0500 Subject: [PATCH] Allow async functions in the Vercel edge middleware integration (#9334) Co-authored-by: Florian Lefebvre Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com> Co-authored-by: lilnasy <69170106+lilnasy@users.noreply.github.com> --- .changeset/young-spoons-rescue.md | 5 +++++ packages/integrations/vercel/src/serverless/middleware.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/young-spoons-rescue.md diff --git a/.changeset/young-spoons-rescue.md b/.changeset/young-spoons-rescue.md new file mode 100644 index 000000000000..6fbeded05974 --- /dev/null +++ b/.changeset/young-spoons-rescue.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Allows the edge middleware to be an async function. diff --git a/packages/integrations/vercel/src/serverless/middleware.ts b/packages/integrations/vercel/src/serverless/middleware.ts index a2e44722b20d..b3ada80d15bf 100644 --- a/packages/integrations/vercel/src/serverless/middleware.ts +++ b/packages/integrations/vercel/src/serverless/middleware.ts @@ -53,7 +53,7 @@ function edgeMiddlewareTemplate(middlewarePath: string, vercelEdgeMiddlewareHand if (existsSync(filePathEdgeMiddleware + '.js') || existsSync(filePathEdgeMiddleware + '.ts')) { const stringified = JSON.stringify(filePathEdgeMiddleware.replace(/\\/g, '/')); handlerTemplateImport = `import handler from ${stringified}`; - handlerTemplateCall = `handler({ request, context })`; + handlerTemplateCall = `await handler({ request, context })`; } else { } return `