honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
19.07k stars 544 forks source link

Parameters being matched against before other paths if they weren't declared last #2601

Closed janat08 closed 5 months ago

janat08 commented 5 months ago

What is the feature you are proposing?

I had a path/:id and a path/another. Declared in that order, and then spend an hour trying to debug it. Can't possibly that big of a performance hit to reorder paths for matching with param paths being last.

janat08 commented 5 months ago

Reordered as in sorted by hono.

NamesMT commented 5 months ago

IMO this is not intuitive as most users would expect what is being declared first to be matched first.

Can't possibly that big of a performance hit to reorder paths for matching with param paths being last.

The complexity and performance hit is bigger than you think on large apps, especially when we consider the proper priority parsing of normal, path parameter, regexp, wildcard, etc.

If this is a blocker for you though, you can write a simple helper function that accesses the app.routes and app.router to perform the sorting to your liking.

janat08 commented 5 months ago

I take it no other route can match if a :paramId route is in front of it.


From: Trung Dang @.> Sent: Sunday, May 5, 2024 11:19 AM To: honojs/hono @.> Cc: zhan ishzhanov @.>; Author @.> Subject: Re: [honojs/hono] Parameters being matched against before other paths if they weren't declared last (Issue #2601)

IMO this is not intuitive as most users would expect what is being declared first to be matched first.

Can't possibly that big of a performance hit to reorder paths for matching with param paths being last. The complexity and performance hit is bigger than you think on large apps, especially when we consider the proper priority parsing of normal, path parameter, regexp, wildcard, etc.

If this is a blocker for you though, you can write a simple helper function that accesses the app.routes and app.router to perform the sorting to your liking.

— Reply to this email directly, view it on GitHubhttps://github.com/honojs/hono/issues/2601#issuecomment-2094648567, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACWP5AMQCRGOJOOXM2G3ENDZAXFN5AVCNFSM6AAAAABHFHAWMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUGY2DQNJWG4. You are receiving this because you authored the thread.Message ID: @.***>