From 22a5405b4a4b7948458ad170b0a7bde6954058c1 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Fri, 5 Jan 2024 18:27:48 +0000 Subject: [PATCH] fix(vercel): include 404.html as fallback in the static adapter (#9591) * include 404.html as fallback * add changeset * include only when 404.astro exists * add test * route.component -> route.pathname --- .changeset/brown-turtles-invite.md | 5 ++++ .../integrations/vercel/src/static/adapter.ts | 5 ++++ .../test/fixtures/static/astro.config.mjs | 6 +++++ .../vercel/test/fixtures/static/package.json | 9 +++++++ .../test/fixtures/static/src/pages/404.astro | 8 ++++++ .../test/fixtures/static/src/pages/one.astro | 8 ++++++ .../test/fixtures/static/src/pages/two.astro | 8 ++++++ .../integrations/vercel/test/static.test.js | 26 +++++++++++++++++++ pnpm-lock.yaml | 9 +++++++ 9 files changed, 84 insertions(+) create mode 100644 .changeset/brown-turtles-invite.md create mode 100644 packages/integrations/vercel/test/fixtures/static/astro.config.mjs create mode 100644 packages/integrations/vercel/test/fixtures/static/package.json create mode 100644 packages/integrations/vercel/test/fixtures/static/src/pages/404.astro create mode 100644 packages/integrations/vercel/test/fixtures/static/src/pages/one.astro create mode 100644 packages/integrations/vercel/test/fixtures/static/src/pages/two.astro create mode 100644 packages/integrations/vercel/test/static.test.js diff --git a/.changeset/brown-turtles-invite.md b/.changeset/brown-turtles-invite.md new file mode 100644 index 000000000000..9150dc0c05bb --- /dev/null +++ b/.changeset/brown-turtles-invite.md @@ -0,0 +1,5 @@ +--- +"@astrojs/vercel": patch +--- + +Fixes an issue where 404.astro was not used in static mode. diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 173a0d9bdb72..44222f9451ce 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -125,6 +125,11 @@ export default function vercelStatic({ continue: true, }, { handle: 'filesystem' }, + ...routes.find(route => route.pathname === "/404") ? [{ + src: `/.*`, + dest: `/404.html`, + status: 404, + }] : [], ], ...(imageService || imagesConfig ? { diff --git a/packages/integrations/vercel/test/fixtures/static/astro.config.mjs b/packages/integrations/vercel/test/fixtures/static/astro.config.mjs new file mode 100644 index 000000000000..55620c240533 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/static/astro.config.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/static'; + +export default defineConfig({ + adapter: vercel() +}); diff --git a/packages/integrations/vercel/test/fixtures/static/package.json b/packages/integrations/vercel/test/fixtures/static/package.json new file mode 100644 index 000000000000..2f2936e31a31 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/static/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-vercel-static", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/vercel": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/vercel/test/fixtures/static/src/pages/404.astro b/packages/integrations/vercel/test/fixtures/static/src/pages/404.astro new file mode 100644 index 000000000000..9e307c5c292c --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/static/src/pages/404.astro @@ -0,0 +1,8 @@ + +
+