简体   繁体   中英

Inversify Express order routes

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?

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')
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM