Static content caching

This commit is contained in:
calzoneman 2014-02-23 23:27:07 -06:00
parent 0f9c3b2dd1
commit cc241da5cf
7 changed files with 25 additions and 5 deletions

View file

@ -32,7 +32,7 @@ function sendJade(res, view, locals) {
var file = path.join(templates, view + ".jade");
var fn = jade.compile(fs.readFileSync(file), {
filename: file,
pretty: true
pretty: !Config.get("http.minify")
});
cache[view] = fn;
}

View file

@ -229,6 +229,16 @@ function handleContactPage(req, res) {
});
}
function static(dir) {
dir = path.join(__dirname, dir);
return function (req, res) {
res.sendfile(req.path.replace(/^\//, ""), {
maxAge: Config.get("http.cache-ttl") * 1000,
root: dir
});
};
}
module.exports = {
/**
* Initializes webserver callbacks
@ -273,7 +283,8 @@ module.exports = {
logRequest(req);
next();
});
app.use(express.static("www"));
//app.use(express.static("www"));
app.use(static(path.join("..", "..", "www")));
},
logRequest: logRequest,