Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var render = function (encoding) {
return function (page, req, res) {
if (encoding && !req.acceptsEncodings(encoding)) {
return false;
}
var content = getContent(page, encoding);
if (content) {
res.set('Content-Encoding', encoding);
res.set('Content-Type', 'text/html');
res.end(content, encoding ? 'binary' : null);
return true;
}
return false;
};
};
var renderers = [
render('br'),
render('gz'),
render()
];
var renderContent = function (page, req, res) {
return _.some(renderers, function (renderer) {
return renderer(page, req, res);
});
};
var showPage = function (req, res, next) {
var page = req.params.page;
if (!renderContent(page, req, res)) {
return next({ status: 404 });
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.