restify / restify/node-restify
Brittle Routing
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
- Used appropriate template for the issue type
- Searched both open and closed issues for duplicates of this issue
- Title adequately and concisely reflects the feature or the bug
Restify Version: 8.5.1
Node.js Version: v14.16.1
Expected behaviour
curl http://localhost:8880/api/users/a766c023-34ec-40d2-923c-e8259a28d2c5 should return Got:/api/users/:id
Actual behaviour
curl http://localhost:8880/api/users/a766c023-34ec-40d2-923c-e8259a28d2c5 returns {"code":"ResourceNotFound","message":"/api/users/a766c023-34ec-40d2-923c
-e8259a28d2c5 does not exist"}
Repro case
var restify = require('restify');
const server = restify.createServer({
name: 'myapp',
version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
const routes = [
'/api/users/award_winners',
'/api/users/admins',
'/api/users/:id',
'/api/:resourceType/',
]
routes.forEach(element => {
server.get(element, function (req, res, next) {
res.send("Got:" + element)
return next();
});
}
);
server.listen(8880, function () {
console.log('%s listening at %s', server.name, server.url);
});
Cause
I think it's related to https://github.com/delvedor/find-my-way/issues/161
⚠️ What is very important and why I think this is a serious bug, is that if you comment out the 1st, 2nd or 4th route the route works. There is something about that trifecta of routes that causes this issue with the 3rd route. Reordering the routes causes issues, and the original application has routes in that order.
We encountered this issue originally while upgrading from an old version of restify, but going forward it means that if anyone adds another route, we could just break other routes in some non obvious way.
Are you willing and able to fix this?
In theory yes, although I'm not sure since I think it's a bug in the dependent project. I just didn't feel it was adequately captured in the bug reports for this project.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied Node.js repro with the four routes and vary their order or remove each route to confirm the routing failure. Compare the behavior with the linked find-my-way issue; done means the parameterized route returns Got:/api/users/:id regardless of route order and neighboring routes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100