Skip to content

Commit

Permalink
fix(vercel): support dynamic paths (#3081)
Browse files Browse the repository at this point in the history
* fix(vercel): support dynamic paths

* Changeset
  • Loading branch information
JuanM04 authored Apr 12, 2022
1 parent f968c05 commit f665d1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-kangaroos-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Support dynamic paths
17 changes: 15 additions & 2 deletions packages/integrations/vercel/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(),
})),
});
},
},
Expand Down

0 comments on commit f665d1a

Please sign in to comment.