2

I'm using inversify-express-utils and I'm looking for a way to set an order for how my endpoints are matched.

eg... using express. The router could have

router.get('/users/me')
router.get('/users/:userId')

and the users/me endpoint would resolve successfully.

But using inversify, I have endpoints and controllers like so (detail left out just to show decorators)

@controller('/users')
   @httpGet('/:userId')
@controller('/users/me')
   @httpGet('/')

It seems like the users/me controller is being registered later, even though I import it earlier, and so it's calling users/:userId with the userId param set to me instead.

Is there a way to sort this?

Matt Wills
  • 676
  • 6
  • 11

1 Answers1

-1

with regex conditions

router.get('users/:userId(^me$)', (req, res) => {

      res.send('it is me')
  });

router.get('users/:userId)', (req, res) => {

      res.send('it is not me')
  });
Oleg
  • 3,580
  • 1
  • 7
  • 12
  • No... that's still using express's native route registration which works fine without this funky workaround – Matt Wills Nov 08 '19 at 10:24
  • Updated my question to be clearer... the point is that we're using this package (https://github.com/inversify/inversify-express-utils) specifically to register endpoints, not express's native express.Router – Matt Wills Nov 08 '19 at 10:29