Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An unofficial package allowing you to create http.Server instances of your Vercel Node lambdas.

License

NotificationsYou must be signed in to change notification settings

ctrlplusb/vercel-node-server

Repository files navigation

An unofficial package allowing you to create Nodehttp.Server instances of yourVercelNode lambdas.

Enables you to write unit/integration tests for your lambdas, or to perform manual testing against a local server instance.

npmMIT LicenseTravisCodecov

Installation

npm install vercel-node-server

Supported API

This package has taken the code from the official@vercel/node builder in order to ensure maximum API compatibility. As far as I am aware we have 100% API coverage.

Unit testing your lambdas

In the below example we will make use of a local server in order to perform an integration test against our lambda.

We will be making use of thetest-listen package, which accepts ahttp.Server instance and will return a unique URL based on an available port.

We will also make use ofaxios in order to make the request against our lambda.

import{createServer}from'vercel-node-server';importlistenfrom'test-listen';importaxiosfrom'axios';importhelloLambdafrom'./api/hello';letserver;leturl;beforeAll(async()=>{server=createServer(routeUnderTest);url=awaitlisten(server);});afterAll(()=>{server.close();});it('should return the expected response',async()=>{constresponse=awaitaxios.get(url,{params:{name:'Pearl'}});expect(response.data).toBe('Hello Pearl');});

Running a local server

Given the following lambda.

consthelloLambda=(req,res)=>{res.send(`Hello${req.query.name}`);};

You can create a Nodehttp.Server instance like so.

import{createServer}from'vercel-node-server';importhelloLambdafrom'./api/hello';constserver=createServer(helloLambda);// start listening on port 8000server.listen(8000);

Then you can then make requests against it.

> curl http://localhost:8000?name=PearlHello Pearl%

About

An unofficial package allowing you to create http.Server instances of your Vercel Node lambdas.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp