Monday, 17 April 2017

Express route being "skipped" for next route

My router setup is as follows:

// app.js
app.use(require('./server/routes/index'));

// index.js
router.use('/', require('./home.js'));
router.use('/inviteParticipants', require('./invite.js'));

// invite.js
router.use('/route1', require('./route1.js'));
router.use('/route2', require('./route2.js'));

// route1.js
router.post('/:key', function(req, res, next) {
  // ..code
}

// route2.js
router.post('/:key', function(req, res, next) {
  // ..code
}

When making a request to both /inviteParticipants/route1 and inviteParticipants/route2, /route2 seems to catch both requests.

However, if I comment out router.use('/route2',...) in invite.js, /route1 will catch it's corresponding route, and the route originally intended for route route2 will simply return a 404.

So, route1 works as intended, but when route2 is available, it seems to catch the request instead. route1 does not use a next() call, if that matters. I have double checked the routes being requested and the route going to route1 is correct.

What could I be doing wrong here to be "skipping" route1?



via skwny

No comments:

Post a Comment