Saturday 29 April 2017

Express route not going to expected handler

I have two routes set up as follows:

router.get('/users', (req, res) => {});

and

router.get('/users/:id', (req, res) => {});

The second route works as expected. It's intended to request a single user object by ID. I intended the first route to return all users. However, if I don't pass an id parameter to the route, express is still routing the request to the second route, just without the id parameter set. Is there any way to get it to go to the first route handler, or do I just have to use only the second route, and check for the existence of the id parameter to determine which results to return?



via Jedediah

No comments:

Post a Comment