Skip to content

Commit 654973b

Browse files
committed
Removed caching when "-s --static" used
1 parent e8dfd09 commit 654973b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

bin/cmd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ program
2525
.description("serve and watch functions")
2626
.action(function(cmd, options) {
2727
console.log("Starting server");
28-
var server = serve.listen(program.port || 9000);
2928
var static = Boolean(program.static);
29+
var server = serve.listen(program.port || 9000, static);
3030
if(static) {
3131
return
3232
}

lib/serve.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ function promiseCallback(promise, callback) {
4343
);
4444
}
4545

46-
function createHandler(dir) {
46+
function createHandler(dir, static) {
4747
return function(request, response) {
4848
var func = request.path.split("/").filter(function(e) {
4949
return e;
5050
})[0];
5151
var module = path.join(process.cwd(), dir, func);
52+
if(static) {
53+
delete require.cache[require.resolve(module)]
54+
}
5255
var handler;
5356
try {
5457
handler = require(module);
@@ -75,7 +78,7 @@ function createHandler(dir) {
7578
};
7679
}
7780

78-
exports.listen = function(port) {
81+
exports.listen = function(port, static) {
7982
var config = conf.load();
8083
var app = express();
8184
var dir = config.build.functions || config.build.Functions;
@@ -88,7 +91,7 @@ exports.listen = function(port) {
8891
app.get("/favicon.ico", function(req, res) {
8992
res.status(204).end();
9093
});
91-
app.all("*", createHandler(dir));
94+
app.all("*", createHandler(dir, static));
9295

9396
app.listen(port, function(err) {
9497
if (err) {

0 commit comments

Comments
 (0)