mtbrault / nextjs-http-supertest

npm package to get an http server parsing your nextJS app to link endpoint with handler
14 stars 5 forks source link

fix: routes not being considered in the correct order #5

Closed justin-caldicott closed 1 year ago

justin-caldicott commented 1 year ago

Expected

If you have the following routes defined: /user/[id] /user/[id]/locations

Then a request to /user/[id]/locations will resolve to that, more specific, route.

Actual

A request to /user/[id]/locations resolves to /user/[id] as it comes across this one first.

Proposed change

This PR sorts the dynamic routes to have the longest routes first, which will ensure that, where routes are nested as such, the most specific route will be chosen.

Testing

Ideally I'd have extended tests to cover this case, but there aren't any and it feels outside of the scope of this change to add them. I've created an issue for this.