Static content caching
This commit is contained in:
parent
0f9c3b2dd1
commit
cc241da5cf
7 changed files with 25 additions and 5 deletions
|
|
@ -26,7 +26,8 @@ var defaults = {
|
|||
host: "",
|
||||
port: 8080,
|
||||
domain: "http://localhost",
|
||||
minify: false
|
||||
minify: false,
|
||||
"cache-ttl": 0
|
||||
},
|
||||
https: {
|
||||
enabled: false,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue