Skip to content

Commit 85f2662

Browse files
authored
Merge pull request netlify#62 from 8eecf0d2/master
Added "-s --static" option to prevent building of files
2 parents d739bb3 + ce3b8c8 commit 85f2662

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

bin/cmd.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ program.version(pkg.version);
1717

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

2223
program
2324
.command("serve <dir>")
2425
.description("serve and watch functions")
2526
.action(function(cmd, options) {
2627
console.log("netlify-lambda: Starting server");
27-
var server = serve.listen(program.port || 9000);
28+
var static = Boolean(program.static);
29+
var server = serve.listen(program.port || 9000, static);
30+
if (static) return // early terminate, don't build
2831
build.watch(cmd, program.config, function(err, stats) {
2932
if (err) {
3033
console.error(err);

lib/serve.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function promiseCallback(promise, callback) {
4343
);
4444
}
4545

46-
function createHandler(dir) {
46+
function createHandler(dir, static) {
4747
return function(request, response) {
4848
// handle proxies without path re-writes (http-servr)
4949
var cleanPath = request.path.replace(/^\/.netlify\/functions/, '')
@@ -52,6 +52,9 @@ function createHandler(dir) {
5252
return e;
5353
})[0];
5454
var module = path.join(process.cwd(), dir, func);
55+
if(static) {
56+
delete require.cache[require.resolve(module)]
57+
}
5558
var handler;
5659
try {
5760
handler = require(module);
@@ -78,7 +81,7 @@ function createHandler(dir) {
7881
};
7982
}
8083

81-
exports.listen = function(port) {
84+
exports.listen = function(port, static) {
8285
var config = conf.load();
8386
var app = express();
8487
var dir = config.build.functions || config.build.Functions;
@@ -91,7 +94,7 @@ exports.listen = function(port) {
9194
app.get("/favicon.ico", function(req, res) {
9295
res.status(204).end();
9396
});
94-
app.all("*", createHandler(dir));
97+
app.all("*", createHandler(dir, static));
9598

9699
app.listen(port, function(err) {
97100
if (err) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "netlify-lambda",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Build and serve lambda function with webpack compilation",
55
"homepage": "https://github.com/netlify/netlify-lambda#readme",
66
"main": "bin/cmd.js",

0 commit comments

Comments
 (0)