- Notifications
You must be signed in to change notification settings - Fork5
An unofficial package allowing you to create http.Server instances of your Vercel Node lambdas.
License
ctrlplusb/vercel-node-server
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
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.
npm install vercel-node-server
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.
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');});
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.