mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
[ci] format
This commit is contained in:
parent
56bd88ae75
commit
efbe8fbd5b
3 changed files with 32 additions and 28 deletions
|
@ -266,7 +266,7 @@ export default defineConfig({
|
||||||
**Type:** `number`<br>
|
**Type:** `number`<br>
|
||||||
**Available for:** Serverless
|
**Available for:** Serverless
|
||||||
|
|
||||||
Use this property to extend or limit the maximum duration (in seconds) that Serverless Functions can run before timing out. See the [Vercel documentation](https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration) for the default and maximum limit for your account plan.
|
Use this property to extend or limit the maximum duration (in seconds) that Serverless Functions can run before timing out. See the [Vercel documentation](https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration) for the default and maximum limit for your account plan.
|
||||||
|
|
||||||
```diff lang="js"
|
```diff lang="js"
|
||||||
// astro.config.mjs
|
// astro.config.mjs
|
||||||
|
|
|
@ -99,7 +99,7 @@ export interface VercelServerlessConfig {
|
||||||
|
|
||||||
/** Whether to create the Vercel Edge middleware from an Astro middleware in your code base. */
|
/** Whether to create the Vercel Edge middleware from an Astro middleware in your code base. */
|
||||||
edgeMiddleware?: boolean;
|
edgeMiddleware?: boolean;
|
||||||
|
|
||||||
/** Whether to split builds into a separate function for each route. */
|
/** Whether to split builds into a separate function for each route. */
|
||||||
functionPerRoute?: boolean;
|
functionPerRoute?: boolean;
|
||||||
|
|
||||||
|
@ -120,7 +120,6 @@ export default function vercelServerless({
|
||||||
edgeMiddleware = false,
|
edgeMiddleware = false,
|
||||||
maxDuration,
|
maxDuration,
|
||||||
}: VercelServerlessConfig = {}): AstroIntegration {
|
}: VercelServerlessConfig = {}): AstroIntegration {
|
||||||
|
|
||||||
if (maxDuration) {
|
if (maxDuration) {
|
||||||
if (typeof maxDuration !== 'number') {
|
if (typeof maxDuration !== 'number') {
|
||||||
throw new TypeError(`maxDuration must be a number`, { cause: maxDuration });
|
throw new TypeError(`maxDuration must be a number`, { cause: maxDuration });
|
||||||
|
@ -143,10 +142,13 @@ export default function vercelServerless({
|
||||||
name: PACKAGE_NAME,
|
name: PACKAGE_NAME,
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
||||||
|
|
||||||
if (maxDuration && maxDuration > 900) {
|
if (maxDuration && maxDuration > 900) {
|
||||||
logger.warn(`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`)
|
logger.warn(
|
||||||
logger.warn(`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`)
|
`maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`
|
||||||
|
);
|
||||||
|
logger.warn(
|
||||||
|
`Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webAnalytics?.enabled || analytics) {
|
if (webAnalytics?.enabled || analytics) {
|
||||||
|
@ -272,7 +274,7 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
|
||||||
NTF_CACHE,
|
NTF_CACHE,
|
||||||
includeFiles: filesToInclude,
|
includeFiles: filesToInclude,
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
maxDuration
|
maxDuration,
|
||||||
});
|
});
|
||||||
routeDefinitions.push({
|
routeDefinitions.push({
|
||||||
src: route.pattern.source,
|
src: route.pattern.source,
|
||||||
|
@ -288,7 +290,7 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
|
||||||
NTF_CACHE,
|
NTF_CACHE,
|
||||||
includeFiles: filesToInclude,
|
includeFiles: filesToInclude,
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
maxDuration
|
maxDuration,
|
||||||
});
|
});
|
||||||
routeDefinitions.push({ src: '/.*', dest: 'render' });
|
routeDefinitions.push({ src: '/.*', dest: 'render' });
|
||||||
}
|
}
|
||||||
|
@ -331,14 +333,14 @@ You can set functionPerRoute: false to prevent surpassing the limit.`
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateFunctionFolderArgs {
|
interface CreateFunctionFolderArgs {
|
||||||
functionName: string
|
functionName: string;
|
||||||
entry: URL
|
entry: URL;
|
||||||
config: AstroConfig
|
config: AstroConfig;
|
||||||
logger: AstroIntegrationLogger
|
logger: AstroIntegrationLogger;
|
||||||
NTF_CACHE: any
|
NTF_CACHE: any;
|
||||||
includeFiles: URL[]
|
includeFiles: URL[];
|
||||||
excludeFiles?: string[]
|
excludeFiles?: string[];
|
||||||
maxDuration?: number
|
maxDuration?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createFunctionFolder({
|
async function createFunctionFolder({
|
||||||
|
|
|
@ -2,18 +2,20 @@ import { loadFixture } from './test-utils.js';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
describe('maxDuration', () => {
|
describe('maxDuration', () => {
|
||||||
/** @type {import('./test-utils.js').Fixture} */
|
/** @type {import('./test-utils.js').Fixture} */
|
||||||
let fixture;
|
let fixture;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/max-duration/',
|
root: './fixtures/max-duration/',
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('makes it to vercel function configuration', async () => {
|
it('makes it to vercel function configuration', async () => {
|
||||||
const vcConfig = JSON.parse(await fixture.readFile('../.vercel/output/functions/render.func/.vc-config.json'));
|
const vcConfig = JSON.parse(
|
||||||
expect(vcConfig).to.deep.include({ maxDuration: 60 });
|
await fixture.readFile('../.vercel/output/functions/render.func/.vc-config.json')
|
||||||
});
|
);
|
||||||
|
expect(vcConfig).to.deep.include({ maxDuration: 60 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue