mock-config-server icon indicating copy to clipboard operation
mock-config-server copied to clipboard

Requests with url params can overwrite similar requests without params

Open RiceWithMeat opened this issue 1 year ago • 1 comments

Now such similar requests have the following problem. If a request with a parameter comes before a request without parameter, then in response to the request without parameters the response for the request with the parameter is sent.

[
  {
  path: '/users/:userId',
  method: 'get',
  routes: [{ data: '/users/:userId data' }]
  },
  {
  path: '/users/list',
  method: 'get',
  routes: [{ data: '/users/list data' }]
  }
]
// GET /users/1 -> '/users/:userId data' - correct
// GET /users/list -> '/users/:userId data' - wrong response

If it's the other way around, then everything works as it should.

[
  {
  path: '/users/list',
  method: 'get',
  routes: [{ data: '/users/list data' }]
  },
  {
  path: '/users/:userId',
  method: 'get',
  routes: [{ data: '/users/:userId data' }]
  }
]
// GET /users/1 -> '/users/:userId data' - correct
// GET /users/list -> '/users/list data' - correct

RiceWithMeat avatar Jul 14 '24 18:07 RiceWithMeat

I may be wrong, but that's how routers work, it's called route priority - https://stackoverflow.com/questions/32603818/order-of-router-precedence-in-express-js

zeroqs avatar Aug 29 '24 13:08 zeroqs

@zeroqs yes you are right but we can do it instead of the users and improve their development experience

MiaInturi avatar Nov 03 '24 18:11 MiaInturi