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

bug/issue 1329 pass custom runtime to API routes for Vercel adapter #1381

Merged
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
2 changes: 1 addition & 1 deletion packages/plugin-adapter-vercel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function vercelAdapter(compilation, options) {
const outputRoot = new URL(`.${basePath}/api/${id}.func/`, adapterOutputUrl);
const { assets = [] } = value;

await setupFunctionBuildFolder(id, outputType, outputRoot);
await setupFunctionBuildFolder(id, outputType, outputRoot, runtime);

await fs.cp(
new URL(outputHref),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* index.js
*/
import chai from 'chai';
import fs from 'fs/promises';
import fs from 'fs';
import glob from 'glob-promise';
import { JSDOM } from 'jsdom';
import path from 'path';
Expand Down Expand Up @@ -65,31 +65,35 @@ describe('Build Greenwood With: ', function() {
let functionFolders;

before(async function() {
configFile = await fs.readFile(new URL('./config.json', vercelOutputFolder), 'utf-8');
configFile = await fs.promises.readFile(new URL('./config.json', vercelOutputFolder), 'utf-8');
functionFolders = await glob.promise(path.join(normalizePathnameForWindows(vercelFunctionsOutputUrl), '**/*.func'));
});

it('should output the expected number of serverless function output folders', function() {
expect(functionFolders.length).to.be.equal(1);
expect(functionFolders.length).to.be.equal(2);
});

it('should output the expected configuration file for the build output', function() {
expect(configFile).to.be.equal('{"version":3}');
});

it('should output the expected package.json for each serverless function', function() {
functionFolders.forEach(async (folder) => {
const packageJson = await fs.readFile(new URL('./package.json', `file://${folder}/`), 'utf-8');

expect(packageJson).to.be.equal('{"type":"module"}');
functionFolders.forEach((folder) => {
fs.readFile(path.join(folder, 'package.json'), 'utf-8', (err, contents) => {
if (!err) {
expect(contents).to.equal('{"type":"module"}');
}
});
});
});

it('should output the expected .vc-config.json for each serverless function with runtime option honored', function() {
functionFolders.forEach(async (folder) => {
const packageJson = await fs.readFile(new URL('./vc-config.json', `file://${folder}/`), 'utf-8');

expect(packageJson).to.be.equal('{"runtime":"nodejs22.x","handler":"index.js","launcherType":"Nodejs","shouldAddHelpers":true}');
functionFolders.forEach((folder) => {
fs.readFile(path.join(folder, '.vc-config.json'), 'utf-8', (err, contents) => {
if (!err) {
expect(contents).to.equal('{"runtime":"nodejs22.x","handler":"index.js","launcherType":"Nodejs","shouldAddHelpers":true}');
}
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export async function handler(request) {
const params = new URLSearchParams(request.url.slice(request.url.indexOf('?')));
const name = params.has('name') ? params.get('name') : 'World';
const body = { message: `Hello ${name}!` };

return new Response(JSON.stringify(body), {
headers: new Headers({
'Content-Type': 'application/json'
})
});
}
Loading