Last active
August 27, 2017 21:59
-
-
Save shiningabdul/320106bb36a7fee566fb541d2181dc44 to your computer and use it in GitHub Desktop.
Sample route setup with middleware
This file contains 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
module.exports = function(app, express) { | |
var router = express.Router(); // get an instance of the express Router | |
// middleware to use for all requests | |
router.use(function(req, res, next) { | |
console.log('Incoming request'); | |
console.log('Body:'); | |
console.log(req.body); | |
console.log('Url:'); | |
console.log(req.url); | |
next(); // make sure we go to the next routes and don't stop here | |
}); | |
var users = require('./api/usersController'); | |
router.route('/users') | |
.post(users.create_a_user); | |
router.route('/users/:id') | |
.get(users.read_a_user); | |
app.use('/', router); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment