From 3be9b6486cbcdcf79ff034f5c10b43effef1d149 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:30:36 +0000 Subject: [PATCH 1/3] allow 404.html to be the catch-all route --- .../integrations/vercel/src/serverless/adapter.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index dd07e723b644..db7f428051e1 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -287,9 +287,15 @@ You can set functionPerRoute: false to prevent surpassing the limit.` excludeFiles, maxDuration, }); - routeDefinitions.push({ src: '/.*', dest: 'render' }); + for (const route of routes) { + if (route.prerender) continue + routeDefinitions.push({ + src: route.pattern.source, + dest: 'render', + }) + } } - + const fourOhFourRoute = routes.find((route) => route.pathname === '/404'); // Output configuration // https://vercel.com/docs/build-output-api/v3#build-output-configuration await writeJson(new URL(`./config.json`, _config.outDir), { @@ -303,6 +309,11 @@ You can set functionPerRoute: false to prevent surpassing the limit.` }, { handle: 'filesystem' }, ...routeDefinitions, + ...fourOhFourRoute ? [{ + src: '/.*', + dest: fourOhFourRoute.prerender ? '/404.html' : 'render', + status: 404, + }] : [], ], ...(imageService || imagesConfig ? { From 13eab6d0b53e01734434a1d8bdd2efa8947b97bc Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:06:35 +0000 Subject: [PATCH 2/3] add test --- .../prerendered-error-pages/astro.config.mjs | 7 ++++++ .../prerendered-error-pages/package.json | 9 ++++++++ .../src/pages/404.astro | 4 ++++ .../src/pages/one.astro | 8 +++++++ .../src/pages/two.astro | 8 +++++++ .../test/prerendered-error-pages.test.js | 23 +++++++++++++++++++ .../integrations/vercel/test/static.test.js | 2 +- pnpm-lock.yaml | 9 ++++++++ 8 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 packages/integrations/vercel/test/fixtures/prerendered-error-pages/astro.config.mjs create mode 100644 packages/integrations/vercel/test/fixtures/prerendered-error-pages/package.json create mode 100644 packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/404.astro create mode 100644 packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/one.astro create mode 100644 packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/two.astro create mode 100644 packages/integrations/vercel/test/prerendered-error-pages.test.js diff --git a/packages/integrations/vercel/test/fixtures/prerendered-error-pages/astro.config.mjs b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/astro.config.mjs new file mode 100644 index 000000000000..b3f5bd362bae --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/serverless'; + +export default defineConfig({ + output: 'server', + adapter: vercel() +}); diff --git a/packages/integrations/vercel/test/fixtures/prerendered-error-pages/package.json b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/package.json new file mode 100644 index 000000000000..5cfc0e24c44d --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-vercel-prerendered-error-pages", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/vercel": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/404.astro b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/404.astro new file mode 100644 index 000000000000..162ff90b6820 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/prerendered-error-pages/src/pages/404.astro @@ -0,0 +1,4 @@ +--- +export const prerender = true +--- +