scratch-www/server/handler.js

28 lines
569 B
JavaScript
Raw Normal View History

var crypto = require('crypto');
2016-04-12 08:23:43 -04:00
var render = require('./render.js');
/**
* Constructor
*/
function Handler (route) {
2016-04-12 08:23:43 -04:00
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);
};