New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router events (enabling route documentation) – feature request #4523
Comments
@mkastner This is a good idea, So we will display the
|
@getspooky Thanks for your postive response to my musings on the router. Yet, I was more leaning toward the idea of the router events being fired only once, when the application starts up. I.e. when the routes are being "mounted". Like in my example here: https://github.com/mkastner/mk-express-router-doc/blob/main/test/index.js If you want the domain, you would have to have an actual request to take place. But then you could simply us a request logger. But that wasn't the concern I was focusing on. What I had in mind was something like: const rootRouter = request('express').router();
const childRouter = request('express').router();
// fires e.g. 'method' event -> {route: '/', method: 'get', handler: ['anonymous'|functionName]);
router.get('/', someHandler);
router.use('/admin', childRouter);
// fires e.g. 'middleware' event -> { parentRoute: '/', route: '/admin', method: '*', handler: ['anonymous',functionName]); I'd like the events explain the structure of routes:
Basically, what I am hoping for is an evented router creation which enables the api programmer to generate a living routing documentation based on the fired informations. |
Hi this is actually something useful |
I am very fond of the express router for it provides a great deal of flexibility. But I have somewhat problems keeping track of all the routes, middleware locations and methods.
It would be great if there was an event implementation that fires up, if e.g. a middleware handler, another route or a method handler is added.
It would then be easy to keep track of the routes and eventually build a documentation.
Since the lines above might not well explain what I have in mind, I have given this some more thought an created a little example module, which is basically a wrapper/decorator for the express router, which sort of mimics and extends the express router behavior.
I hope this example helps explaining why an evented router might be helpful indeed. It's not great code, but rather a quick and dirty hack:
https://github.com/mkastner/mk-express-router-doc
I don't want to be pushing this too far: but if one could add some documentation on the fly to each respective route and path – that would be the icing on the cake.
The text was updated successfully, but these errors were encountered: