thenativeweb / get-routes Goto Github PK
View Code? Open in Web Editor NEWget-routes gets all routes from an Express application.
License: MIT License
get-routes gets all routes from an Express application.
License: MIT License
var express = require("express");
var Router = express.Router;
var app = express();
var router = new Router();
router.get("/test", (req, res) => { res.send(); });
app.use(router);
// ---------
var getRoutes = require("get-routes");
console.log(routes); // empty
It reads that middleware.route
is empty, but doesn't check to see if middleware.handler
is of type Router.
I don't know if this still works. To do something similar I had to use the following code
const getRouter = () => {
return app._router
}
getRouter().stack.forEach(function (r) {
if (r.handle.stack)
r.handle.stack.forEach((item) => {
if (item.route)
console.log(item.route.methods,item.route.path)
})
})
Which is completely different from your code? I am running "express": "^4.16.2"
For routes that use the "all" method get-routes fails with "Invalid method acl". This applies to routes like this:
app.all('/foo/bar', foo.bar);
Either just pull in the one function needed - https://www.npmjs.com/package/lodash.forown
orrr
replace with for of
:
for (const middleware of app._router.stack) { processMiddleware(middleware); }
So I can do a lot more with your version than https://github.com/vijay4495/express-routes-catalogue/blob/master/src/index.ts#L85-L92 but they handle the nested router as recommended by the express generator
app = express();
const indexRouter = express.Router();
indexRouter .get('/', (req, res) => res.send("OK"));
app.use('/', indexRouter);
I think look you just need to loop through middleware.handle.stack if it comes up.. I'll try to get a PR up
Would it be possible to cut a new release for this package? I would like to use the updated dependencies due to some security issues with the version of lodash that is being used in the currently published version.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.