Skip to content

Instantly share code, notes, and snippets.

@cklanac
Last active July 18, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cklanac/661d0f0aae84eebc511eab2c91c94c03 to your computer and use it in GitHub Desktop.
Save cklanac/661d0f0aae84eebc511eab2c91c94c03 to your computer and use it in GitHub Desktop.
View Express Routers (WIP)
app._router.stack.forEach((rts) => {
if (rts.route && rts.route.path){
console.log(rts.route.path)
}
})
app._router.stack.forEach(rts => {
if (rts.handle.stack) {
rts.handle.stack.forEach(rt => {
console.log(' ', rt)
});
}
});
if (require.main === module) {
// Listen for incoming connections
app.listen(PORT, function () {
console.info(`Server listening on ${this.address().port}`);
/*
var route, routes = [];
app._router.stack.forEach(function (middleware) {
if (middleware.route) {
routes.push(middleware.route);
} else if (middleware.name === 'router') {
middleware.handle.stack.forEach(function (handler) {
route = handler.route;
route && routes.push(route);
});
}
});
console.log(route);
console.log(routes);
*/
app._router.stack.forEach(routes => {
if (!routes.route && !routes.handle.stack) {
console.log(routes.name)
}
if (routes.name === '<anonymous>') {
console.log(routes.handle.toString())
}
if (routes.route) {
console.log(routes.route.stack[0].method, routes.route.path)
}
if (routes.handle.stack) {
console.log(routes.regexp.toString().replace('/^\\', '').replace('\\/?(?=\\/|$)/i', ''));
routes.handle.stack.forEach(rts => {
console.log(' ', rts.route.stack[0].method, rts.route.path)
});
}
});
}).on('error', err => {
console.error(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment