1.2.6 • Published 7 years ago
now-local v1.2.6
now-lambda-runner
A tool for locally testing now lambdas.
Installation
Install the tool via
> npm install -g now-lambda-runnerUsage
Let's say that we have the following now.json file:
{
"version": 2,
"builds": [
{ "src": "www/*.js", "use": "@now/node" },
{ "src": "www/index.html", "use": "@now/static" },
{ "src": "www/static/*.*", "use": "@now/static" }
],
"alias": [ "demoit.now.sh" ],
"routes": [
{ "src": "/e/(.*)", "dest": "/www/editor.js?id=$1"},
{ "src": "/static/(.*)", "dest": "/www/static/$1"},
{ "src": "/(.*)", "dest": "/www/index.html"}
]
}We have to go to the folder containing that now.json file and run
> now-lambdaThe result is as follows:
-----------------------------------
Routes:
http://localhost:8004/e/(.*)
http://localhost:8004/static/(.*)
http://localhost:8004/(.*)
-----------------------------------Here's is a list of the things that happen when now-lambda process your now.json file:
- It spins up an expressjs server locally on your machine
- It starts reading the
routesfield in thenow.jsonfile - If the
destpoints to a JavaScript file it passes the request and response objects to the function exported by that file. Or in other words simulates now's lambda functions. - If the
destpoints to a non JavaScript file it simply serves that file as a static resource. - If the
destpoints to something else it assumes that this is a static resource and directly serves the content of the requested resource.
now-lambda does not:
- Read the
buildsfield - Does not use any of the
@now/<...>packages - Does not connect to now's servers
CLI arguments
--config- path tonow.jsonfile--port- by default the local server listens on port 8004. You can change it via this argument.