scratch-www/server/handler.js
2016-04-14 16:22:13 -04:00

27 lines
569 B
JavaScript

var crypto = require('crypto');
var render = require('./render.js');
/**
* Constructor
*/
function Handler (route) {
var output = render(route);
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',
'Etag': '"' + checksum + '"'
});
res.send(output);
};
}
/**
* Export a new instance
*/
module.exports = function (route) {
return new Handler(route);
};