Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Created February 22, 2016 13:15
Show Gist options
  • Select an option

  • Save andrewjmead/37b5ca9068229f4ed49a to your computer and use it in GitHub Desktop.

Select an option

Save andrewjmead/37b5ca9068229f4ed49a to your computer and use it in GitHub Desktop.
Luiscapo - Middleware
var middleware = {
logger: function(req, res, next) {
console.log(new Date().toString());
console.log('Request: ' + req.method + req.originalUrl);
next();
},
requireAuthentication: function(db) {
return function(req, res, next) {
var token = req.get('Auth');
db.user.findByToken(token).then(function(user) {
req.user = user;
next();
}, function() {
res.status(401).send();
});
}
}
};
module.exports = middleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment