express-list-endpoints
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -17,2 +17,8 @@ # Changelog | ||
## v4.0.1 - 2019-05-06 | ||
### Fixed | ||
- Add logic to avoid duplicate paths #40 | ||
## v4.0.0 - 2018-10-14 | ||
@@ -19,0 +25,0 @@ |
{ | ||
"name": "express-list-endpoints", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "A express package to list all registered endoints and its verbs", | ||
@@ -39,8 +39,8 @@ "main": "src/index.js", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"express": "^4.16.4", | ||
"mocha": "^5.0.0" | ||
"mocha": "^6.0.0" | ||
} | ||
} |
@@ -45,3 +45,8 @@ // var debug = require('debug')('express-list-endpoints') | ||
while (hasParams(parsedRegexp)) { | ||
parsedRegexp = parsedRegexp.toString().replace(/\(\?:\(\[\^\\\/]\+\?\)\)/, ':' + params[paramIdx].name) | ||
var paramId = ':' + params[paramIdx].name | ||
parsedRegexp = parsedRegexp | ||
.toString() | ||
.replace(/\(\?:\(\[\^\\\/]\+\?\)\)/, paramId) | ||
paramIdx++ | ||
@@ -67,3 +72,5 @@ } | ||
if (stackItem.route) { | ||
endpoints.push(parseExpressRoute(stackItem.route, basePath)) | ||
var endpoint = parseExpressRoute(stackItem.route, basePath) | ||
endpoints = addEndpoint(endpoints, endpoint) | ||
} else if (stackItem.name === 'router' || stackItem.name === 'bound dispatch') { | ||
@@ -84,9 +91,36 @@ if (regexpExpressRegexp.test(stackItem.regexp)) { | ||
/** | ||
* Ensures the path of the new endpoint isn't yet in the array. | ||
* If the path is already in the array merges the endpoint with the existing | ||
* one, if not, it adds it to the array. | ||
* | ||
* @param {Array} endpoints Array of current endpoints | ||
* @param {Object} newEndpoint New endpoint to be added to the array | ||
* @returns {Array} Updated endpoints array | ||
*/ | ||
var addEndpoint = function (endpoints, newEndpoint) { | ||
var foundEndpointIdx = endpoints.findIndex(function (item) { | ||
return item.path === newEndpoint.path | ||
}) | ||
if (foundEndpointIdx > -1) { | ||
var foundEndpoint = endpoints[foundEndpointIdx] | ||
foundEndpoint.methods = foundEndpoint.methods.concat(newEndpoint.methods) | ||
} else { | ||
endpoints.push(newEndpoint) | ||
} | ||
return endpoints | ||
} | ||
/** | ||
* Returns an array of strings with all the detected endpoints | ||
* @param {Object} app the express/route instance to get the endponts from | ||
* @param {Object} app the express/route instance to get the endpoints from | ||
*/ | ||
var getEndpoints = function (app) { | ||
return parseEndpoints(app) | ||
var endpoints = parseEndpoints(app) | ||
return endpoints | ||
} | ||
module.exports = getEndpoints |
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
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
72472
97