diff --git a/bin/cmd.js b/bin/cmd.js index 4b52c710..86ff44d9 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -17,14 +17,17 @@ program.version(pkg.version); program .option("-c --config ", "additional webpack configuration") - .option("-p --port ", "port to serve from (default: 9000)"); + .option("-p --port ", "port to serve from (default: 9000)") + .option("-s --static", "serve pre-built lambda files") program .command("serve ") .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); diff --git a/lib/serve.js b/lib/serve.js index ec6571b5..d87bca43 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -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/, '') @@ -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); @@ -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; @@ -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) { diff --git a/package.json b/package.json index 86345dd4..88c32d11 100644 --- a/package.json +++ b/package.json @@ -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",