express-list-routes icon indicating copy to clipboard operation
express-list-routes copied to clipboard

return router list as json object

Open rottriges opened this issue 3 years ago • 2 comments

as mentioned in issue #10 with this extension you have the possibility to return a router list as JSON object divided in sub-router-routes.

rottriges avatar Jan 21 '22 15:01 rottriges

A colleague of mine, who works with Windows-based systems, told me that the Windows drive letter is output with the complete path specification. In addition, backslashes are output instead of slashes with Windows. (Example: C:\apiV1\\path\\ ...)

So I created another commit today and converted the path with replace. I am not a regex expert and it may be that this can be solved more nicely or better.

rottriges avatar Feb 04 '22 09:02 rottriges

@rottriges Thank you for the contribution, however, your current impletion has a lot of duplication. Think we can achieve the same result and reuse the existing loops and instead of logging results we just store them in a map and have it always returned.

If I can get some time I will look at refactoring your approach.

Essentially I am thinking we could extend the code at this point, and maybe have option to just disable logging.

  if (options.logger) {
    options.logger(stackMethod, stackSpace, stackPath); 
  }  
  map[stack.routerPath] = [...(map[stack.routerPath] ?? []), { method: stackMethod, path: stackPath, routePath: stack.route.path }]

........

return map;
const routes = expressListRoutes(app, { logger: null });

labithiotis avatar Mar 07 '22 12:03 labithiotis