0
Fork 0
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:
Arsh 2023-11-07 14:01:04 +00:00 committed by GitHub
parent 35739d01e9
commit 754e4fd31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 80 additions and 8 deletions

View 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.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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);
});
});

View 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
View file

@ -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':