Skip to content

Commit

Permalink
Merge pull request #62 from 8eecf0d2/master
Browse files Browse the repository at this point in the history
Added "-s --static" option to prevent building of files
  • Loading branch information
swyxio committed Oct 11, 2018
2 parents d739bb3 + ce3b8c8 commit 85f2662
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ program.version(pkg.version);

program
.option("-c --config <webpack-config>", "additional webpack configuration")
.option("-p --port <port>", "port to serve from (default: 9000)");
.option("-p --port <port>", "port to serve from (default: 9000)")
.option("-s --static", "serve pre-built lambda files")

program
.command("serve <dir>")
.description("serve and watch functions")
.action(function(cmd, options) {
console.log("netlify-lambda: Starting server");
var server = serve.listen(program.port || 9000);
var static = Boolean(program.static);
var server = serve.listen(program.port || 9000, static);
if (static) return // early terminate, don't build
build.watch(cmd, program.config, function(err, stats) {
if (err) {
console.error(err);
Expand Down
9 changes: 6 additions & 3 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function promiseCallback(promise, callback) {
);
}

function createHandler(dir) {
function createHandler(dir, static) {
return function(request, response) {
// handle proxies without path re-writes (http-servr)
var cleanPath = request.path.replace(/^\/.netlify\/functions/, '')
Expand All @@ -52,6 +52,9 @@ function createHandler(dir) {
return e;
})[0];
var module = path.join(process.cwd(), dir, func);
if(static) {
delete require.cache[require.resolve(module)]
}
var handler;
try {
handler = require(module);
Expand All @@ -78,7 +81,7 @@ function createHandler(dir) {
};
}

exports.listen = function(port) {
exports.listen = function(port, static) {
var config = conf.load();
var app = express();
var dir = config.build.functions || config.build.Functions;
Expand All @@ -91,7 +94,7 @@ exports.listen = function(port) {
app.get("/favicon.ico", function(req, res) {
res.status(204).end();
});
app.all("*", createHandler(dir));
app.all("*", createHandler(dir, static));

app.listen(port, function(err) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netlify-lambda",
"version": "1.0.0",
"version": "1.0.1",
"description": "Build and serve lambda function with webpack compilation",
"homepage": "https://github.com/netlify/netlify-lambda#readme",
"main": "bin/cmd.js",
Expand Down

0 comments on commit 85f2662

Please sign in to comment.