Skip to content

Commit

Permalink
Prevent Vercel serverless generate static redirect pages (#8896)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 24, 2023
1 parent d7fff03 commit 5dd1ed5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-steaks-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Prevents the Vercel serverless adapter from generating static redirect pages in hybrid mode
1 change: 1 addition & 0 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default function vercelServerless({
serverEntry: 'entry.mjs',
client: new URL('./static/', outDir),
server: new URL('./dist/', config.root),
redirects: false,
},
vite: {
...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
output: 'hybrid',
adapter: vercel(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-redirects-serverless",
"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>Testing</title>
</head>
<body>
<h1>Testing</h1>
</body>
</html>
Empty file.
28 changes: 28 additions & 0 deletions packages/integrations/vercel/test/redirects-serverless.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';

describe('Redirects Serverless', () => {
/** @type {import('astro/test/test-utils.js').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/redirects-serverless/',
redirects: {
'/one': '/',
'/other': '/subpage',
},
});
await fixture.build();
});

it('does not create .html files', async () => {
let hasErrored = false;
try {
await fixture.readFile('../.vercel/output/static/other/index.html');
} catch {
hasErrored = true;
}
expect(hasErrored).to.equal(true, 'this file should not exist');
});
});
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.

0 comments on commit 5dd1ed5

Please sign in to comment.