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

[node] add support for regions in nodejs runtime functions #11458

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/node/src/index.ts
Expand Up @@ -38,6 +38,7 @@ import {
debug,
isSymbolicLink,
walkParentDirs,
NowBuildError,
} from '@vercel/build-utils';
import type {
File,
Expand Down Expand Up @@ -497,6 +498,14 @@ export const build: BuildV3 = async ({
? true
: undefined;

if (staticConfig?.regions && !Array.isArray(staticConfig.regions)) {
throw new NowBuildError({
code: 'NODEJS_FUNCTION_CONFIG_REGIONS',
message: 'Regions must be a string array when using the nodejs runtime',
link: 'https://vercel.com/docs/edge-network/regions#region-list',
});
}

output = new NodejsLambda({
files: preparedFiles,
handler,
Expand All @@ -505,6 +514,7 @@ export const build: BuildV3 = async ({
shouldAddSourcemapSupport,
awsLambdaHandler,
supportsResponseStreaming,
regions: staticConfig?.regions as string[],
maxDuration: staticConfig?.maxDuration,
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/static-config/src/index.ts
Expand Up @@ -20,6 +20,7 @@ export const BaseFunctionConfigSchema = {
oneOf: [
{
type: 'array',
minItems: 1,
items: { type: 'string' },
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/static-config/test/fixtures/node.js
Expand Up @@ -4,6 +4,7 @@ export const config = {
runtime: 'nodejs',
memory: 1024,
maxDuration: 60,
regions: ['fra1'],
};

export default function (req, res) {
Expand Down
9 changes: 6 additions & 3 deletions packages/static-config/test/index.test.ts
Expand Up @@ -11,6 +11,9 @@ describe('getConfig()', () => {
{
"maxDuration": 60,
"memory": 1024,
"regions": [
"fra1",
],
"runtime": "nodejs",
}
`);
Expand Down Expand Up @@ -44,12 +47,12 @@ describe('getConfig()', () => {
it('should throw an error upon schema validation failure', () => {
const project = new Project();
const sourcePath = join(__dirname, 'fixtures/invalid-schema.js');
let err;
let err: Error | undefined;
try {
getConfig(project, sourcePath);
} catch (_err) {
err = _err;
err = _err as unknown as Error;
}
expect(err.message).toEqual('Invalid data');
expect(err?.message).toEqual('Invalid data');
});
});
3 changes: 3 additions & 0 deletions packages/static-config/test/swc.test.ts
Expand Up @@ -58,6 +58,9 @@ describe('getConfig for swc', () => {
{
"maxDuration": 60,
"memory": 1024,
"regions": [
"fra1",
],
"runtime": "nodejs",
}
`);
Expand Down