Skip to content

Brittle Routing #1873

Open
Open

Description

@SJrX
  • 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.

Activity

  1. mainfraame commented on Oct 27, 2022

    @mainfraame

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions