Created
February 22, 2016 13:15
-
-
Save andrewjmead/37b5ca9068229f4ed49a to your computer and use it in GitHub Desktop.
Luiscapo - Middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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