0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

feat: adapter features, deprecate astro configs (#7839)

This commit is contained in:
Emanuele Stoppa 2023-07-28 10:11:13 +01:00
parent 18a0d229c3
commit 469345aa31
9 changed files with 62 additions and 17 deletions

View file

@ -29,11 +29,21 @@ const SUPPORTED_NODE_VERSIONS: Record<
18: { status: 'current' },
};
function getAdapter(): AstroAdapter {
function getAdapter({
edgeMiddleware,
functionPerRoute,
}: {
edgeMiddleware: boolean;
functionPerRoute: boolean;
}): AstroAdapter {
return {
name: PACKAGE_NAME,
serverEntrypoint: `${PACKAGE_NAME}/entrypoint`,
exports: ['default'],
adapterFeatures: {
edgeMiddleware,
functionPerRoute,
},
};
}
@ -43,6 +53,8 @@ export interface VercelServerlessConfig {
analytics?: boolean;
imageService?: boolean;
imagesConfig?: VercelImageConfig;
edgeMiddleware?: boolean;
functionPerRoute?: boolean;
}
export default function vercelServerless({
@ -51,6 +63,8 @@ export default function vercelServerless({
analytics,
imageService,
imagesConfig,
functionPerRoute = false,
edgeMiddleware = false,
}: VercelServerlessConfig = {}): AstroIntegration {
let _config: AstroConfig;
let buildTempFolder: URL;
@ -112,7 +126,7 @@ export default function vercelServerless({
},
'astro:config:done': ({ setAdapter, config }) => {
throwIfAssetsNotEnabled(config, imageService);
setAdapter(getAdapter());
setAdapter(getAdapter({ functionPerRoute, edgeMiddleware }));
_config = config;
buildTempFolder = config.build.server;
serverEntry = config.build.serverEntry;

View file

@ -2,5 +2,7 @@ import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';
export default defineConfig({
adapter: vercel()
adapter: vercel({
functionPerRoute: true
})
});

View file

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

View file

@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-function-per-route",
"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

@ -2,9 +2,8 @@ import {defineConfig} from "astro/config";
import vercel from "@astrojs/vercel/serverless";
export default defineConfig({
adapter: vercel(),
build: {
excludeMiddleware: true
},
adapter: vercel({
edgeMiddleware: true
}),
output: 'server'
});
});

View file

@ -2,9 +2,8 @@ import {defineConfig} from "astro/config";
import vercel from "@astrojs/vercel/serverless";
export default defineConfig({
adapter: vercel(),
build: {
excludeMiddleware: true
},
adapter: vercel({
edgeMiddleware: true
}),
output: 'server'
});
});

View file

@ -7,11 +7,8 @@ describe('build: split', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/basic/',
root: './fixtures/functionPerRoute/',
output: 'server',
build: {
split: true,
},
});
await fixture.build();
});