0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

Prevent Vercel serverless generate static redirect pages (#8896)

This commit is contained in:
Bjorn Lu 2023-10-24 18:26:34 +08:00 committed by GitHub
parent d7fff03e39
commit 5dd1ed50b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Prevents the Vercel serverless adapter from generating static redirect pages in hybrid mode

View file

@ -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),

View file

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

View file

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

View file

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

View file

@ -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
pnpm-lock.yaml generated
View file

@ -4659,6 +4659,15 @@ importers:
specifier: workspace:*
version: link:../../../../../astro
packages/integrations/vercel/test/fixtures/redirects-serverless:
dependencies:
'@astrojs/vercel':
specifier: workspace:*
version: link:../../..
astro:
specifier: workspace:*
version: link:../../../../../astro
packages/integrations/vercel/test/fixtures/serverless-prerender:
dependencies:
'@astrojs/vercel':