steambap / koa-tree-router

high performance router for Koa
MIT License
138 stars 11 forks source link

Define two routes on one single param prefix #28

Open maybephilipp opened 3 months ago

maybephilipp commented 3 months ago

Hello! Thank you for this package!

I have an issue defining two subpaths for single-wildcarded route prefix:

const socialTypeWildGroup = authRouteGroup.newGroup('/:socialType')

socialTypeWildGroup.delete('/foo', async (ctx) => {})
socialTypeWildGroup.get('/bar', async (ctx) => {})

The router throws: Error: wildcard route ':socialType' conflicts with existing children in path '/api/auth/:socialType/bar'

What am I doing wrong?

maybephilipp commented 3 months ago

UPD:

So the issue is because I had routes defined in the following order:

GET /twitter/authenticate
GET /:socialType/callback

In my point of view the logic must be the following: if there is exact match - use it, otherwise - use wildcard.

I've investigated the root cause of it and updated implementation to support such cases. I will open a PR soon.

The following issue seems to be the same kind of issue: https://github.com/steambap/koa-tree-router/issues/19

maybephilipp commented 3 months ago

@steambap Please review this PR at your convenience. Let me know if you have any concerns/additions. I will publish & use my own version for now. Thanks!

maybephilipp commented 3 months ago

For anyone who want to try the version of pkg with the fix, install: @ogc/koa-tree-router