Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
res.render Override Middleware
/**
* Override res.render to do any pre/post processing
*/
app.use(function(req, res, next) {
var render = res.render;
res.render = function(view, options, fn) {
var self = this,
options = options || {},
req = this.req,
app = req.app,
defaultFn;
if ('function' == typeof options) {
fn = options, options = {};
}
defaultFn = function(err, str){
if (err) return req.next(err);
self.send(str);
};
if ('function' != typeof fn) {
fn = defaultFn;
}
render.call(self, view, options, function(err, str) {
// do whatever post processing you want
fn(err, str);
});
};
next();
});
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.