Skip to content

Instantly share code, notes, and snippets.

@shiningabdul
Last active August 27, 2017 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiningabdul/320106bb36a7fee566fb541d2181dc44 to your computer and use it in GitHub Desktop.
Save shiningabdul/320106bb36a7fee566fb541d2181dc44 to your computer and use it in GitHub Desktop.
Sample route setup with middleware
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