handle vercel.json in static adapter

This commit is contained in:
Nate Moore 2023-03-13 14:33:14 -05:00
parent b62e2b4d25
commit 8c2118fd88

View file

@ -1,6 +1,7 @@
import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro';
import { emptyDir, getVercelOutput, writeJson } from '../lib/fs.js';
import { getRoutesFromVercelJSON } from '../lib/vercel-config.js';
import { getRedirects } from '../lib/redirects.js';
const PACKAGE_NAME = '@astrojs/vercel/static';
@ -41,11 +42,13 @@ export default function vercelStatic({ analytics }: VercelStaticConfig = {}): As
await emptyDir(getVercelOutput(_config.root));
},
'astro:build:done': async ({ routes }) => {
const userRoutes = await getRoutesFromVercelJSON(_config)
// Output configuration
// https://vercel.com/docs/build-output-api/v3#build-output-configuration
await writeJson(new URL(`./config.json`, getVercelOutput(_config.root)), {
version: 3,
routes: [...getRedirects(routes, _config), { handle: 'filesystem' }],
routes: [...userRoutes, ...getRedirects(routes, _config), { handle: 'filesystem' }],
});
},
},