|
|
|
@@ -63,8 +63,8 @@ function sendfile(path, app, pathname, req, res) { |
|
|
|
} |
|
|
|
|
|
|
|
var transformCache = {}; |
|
|
|
function handleTransform(path, req, res, app) { |
|
|
|
var ext = pathlib.extname(req.url).substring(1); |
|
|
|
function handleTransform(stat, path, req, res, app) { |
|
|
|
var ext = pathlib.extname(path).substring(1); |
|
|
|
if (ext === "") |
|
|
|
return false; |
|
|
|
|
|
|
|
@@ -74,9 +74,14 @@ function handleTransform(path, req, res, app) { |
|
|
|
|
|
|
|
if (transformCache[path]) { |
|
|
|
var c = transformCache[path]; |
|
|
|
res.writeHead(c.status, c.headers); |
|
|
|
res.end(c.content); |
|
|
|
return true; |
|
|
|
if (stat.ctime === c.ctime) { |
|
|
|
res.writeHead(c.data.status, c.data.headers); |
|
|
|
res.end(c.data.content); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
console.log("throwing out because ctime."); |
|
|
|
delete transformCache[path]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var data = { content: "", headers: null, status: null }; |
|
|
|
@@ -107,7 +112,10 @@ function handleTransform(path, req, res, app) { |
|
|
|
if (!nocache) { |
|
|
|
data.status = writeStream.status; |
|
|
|
data.headers = writeStream.headers; |
|
|
|
transformCache[path] = data; |
|
|
|
transformCache[path] = { |
|
|
|
data: data, |
|
|
|
ctime: stat.ctime |
|
|
|
}; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
@@ -132,10 +140,6 @@ module.exports = function(root, before) { |
|
|
|
// Join the web root with the request's path name |
|
|
|
var path = pathlib.join(root, pn.replace(before, "")); |
|
|
|
|
|
|
|
// If there's a transform, let that handle it |
|
|
|
if (handleTransform(path, req, res, app)) |
|
|
|
return; |
|
|
|
|
|
|
|
// Send a file |
|
|
|
function send(path) { |
|
|
|
sendfile(path, app, pn, req, res); |
|
|
|
@@ -172,7 +176,11 @@ module.exports = function(root, before) { |
|
|
|
path = pathlib.join(path, "index.html"); |
|
|
|
} |
|
|
|
|
|
|
|
// Send the file |
|
|
|
// If there's a transform, let that handle it |
|
|
|
if (handleTransform(stat, path, req, res, app)) |
|
|
|
return; |
|
|
|
|
|
|
|
// Otherwise, send the file |
|
|
|
send(path); |
|
|
|
}); |
|
|
|
} |