Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created January 30, 2012 21:03
Show Gist options
  • Save shiawuen/1706682 to your computer and use it in GitHub Desktop.
Save shiawuen/1706682 to your computer and use it in GitHub Desktop.
Async dynamic helper for Express
var yourAsyncDynamicHelper = require('./yourAsyncDynamicHelper')
app.configure(function(){
//
// other middlewares
//
app.use(yourAsyncDynamicHelper());
//
// other middlewares
//
});
app.dynamicHelpers({
data: function(req, res) { return req.your.dynamic.data; }
});
module.exports = function(options) {
return function(req, res, next) {
// do your async stuff here to get your data
req.your.dynamic.data = 'some async data';
next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment