Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vercel): enable streaming support out of the box #1514

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { withoutLeadingSlash } from "ufo";
import { writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";
import type { VercelBuildConfigV3 } from "../types/presets";
import type {
VercelBuildConfigV3,
VercelServerlessFunctionConfig,
} from "../types/presets";

// https://vercel.com/docs/build-output-api/v3

Expand Down Expand Up @@ -36,11 +39,12 @@ export const vercel = defineNitroPreset({
nitro.options.output.serverDir,
".vc-config.json"
);
const functionConfig = {
const functionConfig: VercelServerlessFunctionConfig = {
runtime: runtimeVersion,
handler: "index.mjs",
launcherType: "Nodejs",
shouldAddHelpers: false,
supportsResponseStreaming: true,
...nitro.options.vercel?.functions,
};
await writeFile(
Expand Down
35 changes: 30 additions & 5 deletions src/types/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,43 @@ export interface VercelBuildConfigV3 {
}[];
}

/**
* https://vercel.com/docs/build-output-api/v3/primitives#serverless-function-configuration
*/
export interface VercelServerlessFunctionConfig {
/**
* Amount of memory (RAM in MB) that will be allocated to the Serverless Function.
*/
memory?: number;

/**
* Maximum execution duration (in seconds) that will be allowed for the Serverless Function.
*/
maxDuration?: number;

/**
* True if a custom runtime has support for Lambda runtime wrappers.
*/
supportsWrapper?: boolean;

/**
* When true, the Serverless Function will stream the response to the client.
*/
supportsResponseStreaming?: boolean;

[key: string]: unknown;
}

export interface PresetOptions {
vercel: {
config: VercelBuildConfigV3;

/**
* If you are using `vercel-edge`, you can specify the region(s) for your edge function.
* @see https://vercel.com/docs/concepts/functions/edge-functions#edge-function-regions
*/
regions?: string[];
functions?: {
memory: number;
maxDuration: number;
[key: string]: unknown;
};

functions?: VercelServerlessFunctionConfig;
};
}