From f665d1a250ef34a9d1cbced9e4441c7e2dc246b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Tue, 12 Apr 2022 11:02:59 -0300 Subject: [PATCH] fix(vercel): support dynamic paths (#3081) * fix(vercel): support dynamic paths * Changeset --- .changeset/quick-kangaroos-notice.md | 5 +++++ packages/integrations/vercel/src/index.ts | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .changeset/quick-kangaroos-notice.md diff --git a/.changeset/quick-kangaroos-notice.md b/.changeset/quick-kangaroos-notice.md new file mode 100644 index 000000000000..4b9fb1d1f979 --- /dev/null +++ b/.changeset/quick-kangaroos-notice.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Support dynamic paths diff --git a/packages/integrations/vercel/src/index.ts b/packages/integrations/vercel/src/index.ts index 22dbc3eef063..dea059b291d3 100644 --- a/packages/integrations/vercel/src/index.ts +++ b/packages/integrations/vercel/src/index.ts @@ -1,4 +1,4 @@ -import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; +import type { AstroAdapter, AstroConfig, AstroIntegration, RouteData } from 'astro'; import type { PathLike } from 'fs'; import fs from 'fs/promises'; import esbuild from 'esbuild'; @@ -67,16 +67,29 @@ export default function vercel(): AstroIntegration { await fs.rm(tmpDir, { recursive: true }); + let staticRoutes: RouteData[] = []; + let dynamicRoutes: RouteData[] = []; + + for (const route of routes) { + if (route.params.length === 0) staticRoutes.push(route); + else dynamicRoutes.push(route); + } + // Routes Manifest // https://vercel.com/docs/file-system-api#configuration/routes await writeJson(new URL(`./routes-manifest.json`, _config.outDir), { version: 3, basePath: '/', pages404: false, - rewrites: routes.map((route) => ({ + rewrites: staticRoutes.map((route) => ({ source: route.pathname, + regex: route.pattern.toString(), destination: `/${ENTRYFILE}`, })), + dynamicRoutes: dynamicRoutes.map((route) => ({ + page: `/${ENTRYFILE}`, + regex: route.pattern.toString(), + })), }); }, },