References:
Last active
July 18, 2018 13:50
-
-
Save cklanac/661d0f0aae84eebc511eab2c91c94c03 to your computer and use it in GitHub Desktop.
View Express Routers (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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