kwhitley / itty-router

A little router.
MIT License
1.7k stars 77 forks source link

Can I list all routes defined by a router #193

Closed casertap closed 7 months ago

casertap commented 7 months ago

Hi, I would like my server to print all routes at startup. Is there a way to achieve that? The documentation does not say.

Thanks

kwhitley commented 7 months ago

Hey Pierre!

There's not a built-method to do that, but we allow a bit of introspection on the routes through router.routes. Each route contains the dense array of match values, including the original route for convenience. This won't show you the routes of child routers (I’m sure you may be able to create something that could).

Hope this helps (and we'll be sure to add a section to the docs)!

casertap commented 7 months ago

Shame there isn't anything out of the box. My API currently returning 404 because not matching any route but I find it difficult to debug

kwhitley commented 7 months ago

Totally get it... in order to maintain the absurd(ly tiny) file size, we specifically include the minimal quality of life bits that can typically get the job done, knowing that the community is definitely encouraged to add their own additional layers/wrappers/utilities around it!

I’m totally happy to help you debug if you want to point me to a repo, but usually I find a miss like that is because I forgot to return from the actual handler in question... without a return, the router just keeps trying to match until all routes are exhausted

casertap commented 7 months ago

It makes sense. Thanks for clarifying, I will double check my returns. Closing this one. Cheers