node-restify icon indicating copy to clipboard operation
node-restify copied to clipboard

multi-parametric routing not populating req.params

Open jack828 opened this issue 4 years ago • 0 comments

Hi. Thanks for a great library. I'll preface this by stating that I am upgrading some VERY legacy code (restify v4 to v8) and such have had a world of pain in doing so.

  • [x] Used appropriate template for the issue type
  • [x] Searched both open and closed issues for duplicates of this issue
  • [x] Title adequately and concisely reflects the feature or the bug

Restify Version: 8.5.1 Node.js Version: 14.16.1

Expected behaviour

My req.params should be populated on all routes.

Actual behaviour

My req.params is only populated on a single route.

Repro case

const restify = require('restify')

const server = restify.createServer({})
const echoParams = (name) => (req, res, next) => {
  res.send(JSON.stringify({ params: req.params, name }))
}
server.get('/:width/:height/:mode/*', echoParams('mode'))
server.get('/:width/:height/*', echoParams('both'))
server.get('/:width/*', echoParams('width'))

server.listen(1234, () => {
  console.log('listen')
})

It does not matter what order I register my routes in, I get the same behaviour:

➜ curl localhost:1234/100/200/fill/test
"{\"params\":{\"width\":\"100\",\"height\":\"200\",\"mode\":\"fill\",\"*\":\"test\"},\"name\":\"mode\"}"%                                                                                                                                                       
➜ curl localhost:1234/100/200/test
"{\"params\":{\"*\":\"test\"},\"name\":\"both\"}"%
➜ curl localhost:1234/100/test
"{\"params\":{\"*\":\"test\"},\"name\":\"width\"}"%

Cause

I wish I knew.

EDIT: I looked at the code and dumped a ton of logging in there and can see the stuff returned here does not contain it either: https://github.com/restify/node-restify/blob/master/lib/router.js#L84

I can't open an issue on find-my-way as this uses an extremely out of date version of it.

Are you willing and able to fix this?

Sure, if someone can point me in the right direction.

Double EDIT: I've abandoned restify because of this issue. I don't believe this package to be maintained or suitable anymore - express works just fine.

jack828 avatar Apr 30 '21 17:04 jack828