siberiacancode / mock-config-server

🎉 tool that easily and quickly imitates server operation, create full fake api in few steps
https://www.npmjs.com/package/mock-config-server
MIT License
91 stars 4 forks source link

Requests with url params can overwrite similar requests without params #184

Closed RiceWithMeat closed 1 day ago

RiceWithMeat commented 4 months ago

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
zeroqs commented 2 months ago

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

MiaInturi commented 1 week ago

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