Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brittle Routing #1873

Open
3 tasks done
SJrX opened this issue Apr 27, 2021 · 1 comment
Open
3 tasks done

Brittle Routing #1873

SJrX opened this issue Apr 27, 2021 · 1 comment

Comments

@SJrX
Copy link

SJrX commented Apr 27, 2021

  • 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 delvedor/find-my-way#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.

@mainfraame
Copy link

ditto. This has caused me much pain and actually motivated me to move away from restify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants