2015-09-04 01:26:56 -04:00
|
|
|
var crypto = require('crypto');
|
|
|
|
|
2016-04-12 08:23:43 -04:00
|
|
|
var render = require('./render.js');
|
2015-10-20 10:51:33 -04:00
|
|
|
|
2015-09-04 01:26:56 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
function Handler (route) {
|
2016-04-12 08:23:43 -04:00
|
|
|
var output = render(route);
|
2015-09-04 01:26:56 -04:00
|
|
|
var checksum = crypto.createHash('md5').update(output).digest('hex');
|
|
|
|
|
|
|
|
return function (req, res) {
|
|
|
|
res.set({
|
|
|
|
'Content-Type': 'text/html',
|
|
|
|
'Cache-Control': 'public, max-age=31536000',
|
2016-01-14 15:54:10 -05:00
|
|
|
'Etag': '"' + checksum + '"'
|
2015-09-04 01:26:56 -04:00
|
|
|
});
|
|
|
|
res.send(output);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export a new instance
|
|
|
|
*/
|
|
|
|
module.exports = function (route) {
|
|
|
|
return new Handler(route);
|
|
|
|
};
|