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:
parent
64a8470ddb
commit
22a5405b4a
9 changed files with 84 additions and 0 deletions
5
.changeset/brown-turtles-invite.md
Normal file
5
.changeset/brown-turtles-invite.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/vercel": patch
|
||||
---
|
||||
|
||||
Fixes an issue where 404.astro was not used in static mode.
|
|
@ -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
|
||||
? {
|
||||
|
|
6
packages/integrations/vercel/test/fixtures/static/astro.config.mjs
vendored
Normal file
6
packages/integrations/vercel/test/fixtures/static/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/static';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel()
|
||||
});
|
9
packages/integrations/vercel/test/fixtures/static/package.json
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/static/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/astro-vercel-static",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/vercel": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
8
packages/integrations/vercel/test/fixtures/static/src/pages/404.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/static/src/pages/404.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>404</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>404</h1>
|
||||
</body>
|
||||
</html>
|
8
packages/integrations/vercel/test/fixtures/static/src/pages/one.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/static/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>One</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>One</h1>
|
||||
</body>
|
||||
</html>
|
8
packages/integrations/vercel/test/fixtures/static/src/pages/two.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/static/src/pages/two.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Two</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Two</h1>
|
||||
</body>
|
||||
</html>
|
26
packages/integrations/vercel/test/static.test.js
Normal file
26
packages/integrations/vercel/test/static.test.js
Normal 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
9
pnpm-lock.yaml
generated
|
@ -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':
|
||||
|
|
Loading…
Add table
Reference in a new issue