sholladay / pogo

Server framework for Deno
Mozilla Public License 2.0
482 stars 33 forks source link

[Question] Check if handler already exists for route #65

Closed KaKi87 closed 2 years ago

KaKi87 commented 2 years ago

Hello,

Is it possible to programmatically check if an handler already exists for a specific route ?

Thanks

sholladay commented 2 years ago

You can inspect the existing routes in the routing table by looking at server.router. In particular, the router has a routes property and a lookup() method.

So, for example, you could do something like this:

const route = server.router.lookup('GET', '/');
const hasHandler = Boolean(route?.handler);

Admittedly, the documentation for those APIs is a bit sparse. PRs welcome to expand upon it.

KaKi87 commented 2 years ago

I actually needed server.router.routes.list, thanks !

sholladay commented 2 years ago

Very cool, thanks for sharing your usage of it.

By the way, I'm working on #62 and those changes will likely fix your bug #66 at the same time. Let me know if you have any other suggestions, as I'm planning a new release soon.

KaKi87 commented 2 years ago

Alright !

Well, I implemented everything I needed to automate in this route.js file :

One last thing I'm missing is Sentry (or alternative) integration but that's up to them (getsentry/sentry-javascript#3009).

KaKi87 commented 2 years ago

Oh and I needed BasicAuth too.