Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ Here's is a list of the things that happen when `now-lambda` process your `now.j
## CLI arguments

* `--config` - path to `now.json` file
* `--port` - by default the local server listens on port 8004. You can change it via this argument.
* `--port` - by default the local server listens on port 8004. You can change it via this argument.
* `--proxy` - a URL to use as a fallback proxy for requests that would otherwise fail (e.g. `http://localhost:3000`)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add one sentence saying that this is not a standard now/zeit feature. It is built here for convenience.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look, will do!

Will add to the read README - let me know if you like the inline help to be more explicit too (was torn between keeping it short and explaining a bit more).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine.

16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const yargs = require('yargs');
const NamedRegExp = require('named-regexp-groups');
const cors = require('cors');
const extglob = require('extglob');
const mime = require('mime-types')
const mime = require('mime-types');
const request = require('request');

const argv = yargs
.options({
Expand All @@ -21,7 +22,12 @@ const argv = yargs
type: 'number',
default: 8004,
desc: 'The port where the runner is listening for your requests'
}
},
proxy: {
type: 'string',
default: null,
desc: 'A URL to use as a fallback proxy for requests that would otherwise fail (e.g. "http://localhost:3000")'
},
})
.help()
.argv;
Expand Down Expand Up @@ -131,6 +137,10 @@ if (fs.existsSync(nowConfPath)) {
obj(req, res)

delete require.cache[require.resolve(handlerFilepath)];
} else if (argv.proxy) {
const proxy = request(`${argv.proxy}${req.url}`)
req.pipe(proxy)
proxy.pipe(res)
} else if (fs.existsSync(handlerFilepath)) {
console.log(logMessage.join('\n'));
sendFile(res, handlerFilepath);
Expand Down Expand Up @@ -158,4 +168,4 @@ if (fs.existsSync(nowConfPath)) {
});
} else {
error('now.json can not be found in ' + nowConfPath);
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "now-lambda-runner",
"version": "3.3.0",
"version": "3.4.0",
"bin": {
"now-lambda": "./index.js"
},
Expand Down Expand Up @@ -28,6 +28,7 @@
"extglob": "3.0.0",
"mime-types": "2.1.21",
"named-regexp-groups": "^1.0.3",
"request": "^2.88.0",
"yargs": "12.0.5"
}
}
Loading