mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
feat(vercel): streaming (#8879)
This commit is contained in:
parent
35739d01e9
commit
754e4fd31c
9 changed files with 80 additions and 8 deletions
7
.changeset/tricky-clocks-end.md
Normal file
7
.changeset/tricky-clocks-end.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
'@astrojs/vercel': minor
|
||||
---
|
||||
|
||||
The Vercel adapter now streams responses!
|
||||
|
||||
This brings better performance to your visitors by showing them content as it is rendered. The browser can also start loading the required stylesheets and scripts much sooner, which ultimately results in faster full page loads.
|
|
@ -341,7 +341,7 @@ interface CreateFunctionFolderArgs {
|
|||
NTF_CACHE: any;
|
||||
includeFiles: URL[];
|
||||
excludeFiles?: string[];
|
||||
maxDuration?: number;
|
||||
maxDuration: number | undefined;
|
||||
}
|
||||
|
||||
async function createFunctionFolder({
|
||||
|
@ -381,6 +381,7 @@ async function createFunctionFolder({
|
|||
handler,
|
||||
launcherType: 'Nodejs',
|
||||
maxDuration,
|
||||
supportsResponseStreaming: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
7
packages/integrations/vercel/test/fixtures/streaming/astro.config.mjs
vendored
Normal file
7
packages/integrations/vercel/test/fixtures/streaming/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
output: "server",
|
||||
adapter: vercel()
|
||||
});
|
10
packages/integrations/vercel/test/fixtures/streaming/package.json
vendored
Normal file
10
packages/integrations/vercel/test/fixtures/streaming/package.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@test/vercel-streaming",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/vercel": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
8
packages/integrations/vercel/test/fixtures/streaming/src/pages/one.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/streaming/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/streaming/src/pages/two.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/streaming/src/pages/two.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Two</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Two</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -7,9 +7,10 @@ describe('Static Assets', () => {
|
|||
|
||||
const VALID_CACHE_CONTROL = 'public, max-age=31536000, immutable';
|
||||
|
||||
async function build({ adapter, assets }) {
|
||||
async function build({ adapter, assets, output }) {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/static-assets/',
|
||||
output,
|
||||
adapter,
|
||||
build: {
|
||||
assets,
|
||||
|
@ -38,31 +39,31 @@ describe('Static Assets', () => {
|
|||
}
|
||||
|
||||
describe('static adapter', async () => {
|
||||
const adapter = await import('@astrojs/vercel/static');
|
||||
const { default: vercel } = await import('@astrojs/vercel/static');
|
||||
|
||||
it('has cache control', async () => {
|
||||
await build({ adapter });
|
||||
await build({ adapter: vercel() });
|
||||
checkValidCacheControl();
|
||||
});
|
||||
|
||||
it('has cache control other assets', async () => {
|
||||
const assets = '_foo';
|
||||
await build({ adapter, assets });
|
||||
await build({ adapter: vercel(), assets });
|
||||
checkValidCacheControl(assets);
|
||||
});
|
||||
});
|
||||
|
||||
describe('serverless adapter', async () => {
|
||||
const adapter = await import('@astrojs/vercel/serverless');
|
||||
const { default: vercel } = await import('@astrojs/vercel/serverless');
|
||||
|
||||
it('has cache control', async () => {
|
||||
await build({ adapter });
|
||||
await build({ output: "server", adapter: vercel() });
|
||||
checkValidCacheControl();
|
||||
});
|
||||
|
||||
it('has cache control other assets', async () => {
|
||||
const assets = '_foo';
|
||||
await build({ adapter, assets });
|
||||
await build({ output: "server", adapter: vercel(), assets });
|
||||
checkValidCacheControl(assets);
|
||||
});
|
||||
});
|
||||
|
|
21
packages/integrations/vercel/test/streaming.test.js
Normal file
21
packages/integrations/vercel/test/streaming.test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
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/streaming/',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('makes it to vercel function configuration', async () => {
|
||||
const vcConfig = JSON.parse(
|
||||
await fixture.readFile('../.vercel/output/functions/render.func/.vc-config.json')
|
||||
);
|
||||
expect(vcConfig).to.deep.include({ supportsResponseStreaming: true });
|
||||
});
|
||||
});
|
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
|
@ -4731,6 +4731,15 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/vercel/test/fixtures/streaming:
|
||||
dependencies:
|
||||
'@astrojs/vercel':
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server:
|
||||
dependencies:
|
||||
'@astrojs/vercel':
|
||||
|
|
Loading…
Add table
Reference in a new issue