uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.95k stars 570 forks source link

Parameter routes routing issue #1012

Closed S-Abhishek closed 8 months ago

S-Abhishek commented 8 months ago

Hey,

I am facing an issue with parameter based routes on latest version of uWebsockets.js (v20.40.0),

To illustrate the problem, I have created an example app below:

const uWS = require('uWebSockets.js');

const app = uWS.App()
  .get('/something/:id/sync', (res, req) => {
    res.end('sync endpoint');
  })  
  .get('/something/:somethingId/pin', (res, req) => {
    res.end('pin endpoint');
  })
  .get('/something/:id/:attribute', (res, req) => {
    res.end('attribute endpoint');
  })
  .listen(9000, (token) => {
    if (token) {
      console.log('Listening to port ' + 9000);
    } else {
      console.log('Failed to listen to port ' + port);
    }
  });

In this application, Request GET /something/1234/pin returns attribute endpoint as result while expected response is pin endpoint.

I went through the routing strategy of uWebsockets which mentions that routes are matched in the order of specificity which implies that pin endpoint should be the above response.

Also, if :somethingId is changed to :id, routing works as expected. Would like to understand if this is a bug with uWebsockets.

Thank you!

uNetworkingAB commented 8 months ago

Stellar bug report, it is fixed and tested in https://github.com/uNetworking/uWebSockets/commit/fc2b7be765983fbce8a3839bc3ff16b51c81b44b

uNetworkingAB commented 8 months ago

Try https://github.com/uNetworking/uWebSockets.js/releases/tag/v20.41.0