Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vercel): include 404.html as fallback in the static adapter #9591

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-turtles-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/vercel": patch
---

Fixes an issue where 404.astro was not used in static mode.
5 changes: 5 additions & 0 deletions packages/integrations/vercel/src/static/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export default function vercelStatic({
continue: true,
},
{ handle: 'filesystem' },
...routes.find(route => route.pathname === "/404") ? [{
ematipico marked this conversation as resolved.
Show resolved Hide resolved
src: `/.*`,
dest: `/404.html`,
status: 404,
}] : [],
],
...(imageService || imagesConfig
? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/static';

export default defineConfig({
adapter: vercel()
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-static",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>404</title>
</head>
<body>
<h1>404</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>One</title>
</head>
<body>
<h1>One</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Two</title>
</head>
<body>
<h1>Two</h1>
</body>
</html>
26 changes: 26 additions & 0 deletions packages/integrations/vercel/test/static.test.js
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.