express-ls-routes
Advanced tools
Comparing version 0.1.1 to 1.0.2
@@ -5,15 +5,41 @@ var flatten = require('lodash-node/modern/arrays/flatten') | ||
const isExpress3 = function (app) { | ||
return app._router.map != null | ||
} | ||
const mapExpress3Routes = function (app) { | ||
var routesMap = app._router.map | ||
var methods = Object.keys(routesMap) | ||
return flatten(methods.map(function (method) { | ||
return routesMap[method].map(function (route) { | ||
return format.method(method) + route.path | ||
}) | ||
})) | ||
} | ||
const mapExpress4Routes = function (app) { | ||
var ignoredRoutes = ['query', 'expressInit'] | ||
return flatten(app._router.stack | ||
.filter(function (entry) { | ||
return ignoredRoutes.indexOf(entry.name) === -1 | ||
}) | ||
.map(function (entry) { | ||
var route = entry.route | ||
return Object.keys(route.methods) | ||
.filter(function (method) { | ||
return !!route.methods[method] | ||
}) | ||
.map(function (method) { | ||
return format.method(method) + route.path | ||
}) | ||
}) | ||
) | ||
} | ||
module.exports = function (app, options) { | ||
return function (req, res, next) { | ||
var routesMap = app._router.map | ||
var methods = Object.keys(routesMap) | ||
var routes = flatten(methods.map(function (method) { | ||
return routesMap[method].map(function (route) { | ||
return format.method(method) + route.path | ||
}) | ||
})) | ||
req.routes = routes | ||
req.routes = isExpress3(app) ? mapExpress3Routes(app) : mapExpress4Routes(app) | ||
next() | ||
} | ||
} |
{ | ||
"name": "express-ls-routes", | ||
"version": "0.1.1", | ||
"version": "1.0.2", | ||
"description": "Cli and middleware to list routes in your express app", | ||
@@ -22,2 +22,5 @@ "main": "index.js", | ||
"homepage": "https://github.com/jaketrent/express-ls-routes", | ||
"scripts": { | ||
"test": "node_modules/mocha/bin/mocha --harmony \"test/unit/**/*.spec.coffee\"" | ||
}, | ||
"bin": { | ||
@@ -28,3 +31,9 @@ "routes": "./bin/cli.js" | ||
"lodash-node": "~2.4.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "^1.7.1", | ||
"mocha": "^1.20.1", | ||
"rf-release": "^0.1.2", | ||
"should": "^4.0.4" | ||
} | ||
} | ||
} |
express-ls-routes | ||
================= | ||
*Updated: supports express3 and express4!* | ||
It's a cli that lets you list the routes in your express app: | ||
@@ -5,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
50247
23
90
0
106
4
3