0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

fix(vercel): support dynamic paths (#3081)

* fix(vercel): support dynamic paths

* Changeset
This commit is contained in:
Juan Martín Seery 2022-04-12 11:02:59 -03:00 committed by GitHub
parent 2ca4343d02
commit 6b8d01e623

View file

@ -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(),
})),
});
},
},