Skip to content

Added "-s --static" option to prevent building of files #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2018
Merged
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
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