0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

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
This commit is contained in:
Arsh 2024-01-05 18:27:48 +00:00 committed by GitHub
parent 64a8470ddb
commit 22a5405b4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/vercel": patch
---
Fixes an issue where 404.astro was not used in static mode.

View file

@ -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
? {

View file

@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/static';
export default defineConfig({
adapter: vercel()
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-static",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>404</title>
</head>
<body>
<h1>404</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>One</title>
</head>
<body>
<h1>One</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Two</title>
</head>
<body>
<h1>Two</h1>
</body>
</html>

View file

@ -0,0 +1,26 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
describe('maxDuration', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/static/',
});
await fixture.build();
});
it('falls back to 404.html', async () => {
const deploymentConfig = JSON.parse(
await fixture.readFile('../.vercel/output/config.json')
);
// change the index if necesseary
expect(deploymentConfig.routes[2]).to.deep.include({
src: '/.*',
dest: '/404.html',
status: 404
});
});
});

9
pnpm-lock.yaml generated
View file

@ -4785,6 +4785,15 @@ importers:
specifier: workspace:*
version: link:../../../../../astro
packages/integrations/vercel/test/fixtures/static:
dependencies:
'@astrojs/vercel':
specifier: workspace:*
version: link:../../..
astro:
specifier: workspace:*
version: link:../../../../../astro
packages/integrations/vercel/test/fixtures/static-assets:
dependencies:
'@astrojs/vercel':