albertofdzm / express-list-endpoints Goto Github PK
View Code? Open in Web Editor NEWA express package to list all registered endpoints and its verbs
License: MIT License
A express package to list all registered endpoints and its verbs
License: MIT License
When I declare path's methods sequentially using the router object, the multiple entries are generated for each method instead of aggregating the methods under the route.
Example:
const express = require('express');
const listEndpoints = require('express-list-endpoints');
const app = express();
const router = express.Router();
router.post('/', (req, res, next) => {
return res.json({ hello: 'world' });
}).delete('/', (req, res, next) => {
return res.json({ goodbye: 'world' });
});
app.use('/test', router);
console.log(listEndpoints(app));
Expected output:
[ { path: '/test', methods: [ 'POST', 'DELETE' ] } ]
Actual output:
[ { path: '/test', methods: [ 'POST' ] },
{ path: '/test', methods: [ 'DELETE' ] } ]
Let me know if you need any help maintaining this. I was just about to build this module myself after getting frustrated at the other express-list-routes
module being poorly written, when I found this!
test
Implement a build script that:
[UNRELEASED]
tag to the current date and versionThe correct path is not being parsed on multi-level baseRoute
, ie:
const express = require('express')
const router = express.Router()
router.route('/my/path').get(()=>{ /* someMethod() */ })
app.use("/api/multi/level", router)
will output:
[ { path: '/api/my/path',
methods: [ 'GET' ] } ]
the output path ^^^^ is incorrect - and the endpoint /api/multi/level/my/path
DOES exist when starting up the server and hitting it in the browser.
Branch | Build failing π¨ |
---|---|
Dependency | eslint-plugin-standard |
Current Version | 2.1.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint-plugin-standard is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
Talk about the arguments and the returned data.
As i use this awesome library to create an ACL module in combination with path-to-regexp
, I can list and show route based permissions. So if we can add something like this :
router
.get('/posts',(req,res)=>{
req.title = 'Get Posts' ;
req.description = 'get a paginated list of posts and ...' ;
...
})
It will be more awesome.
Implement CI using travis
I tried modifying the getEndpoints function to treat asyncRouter like a router, but that doesn't work (all of the object members appear to be functions). My JS-fu is weak, is there a way to fix this?
Branch | Build failing π¨ |
---|---|
Dependency | eslint |
Current Version | 3.10.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
β continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
β bitHound - Dependencies Details
β bitHound - Code Details
β codecov/project 100% (+0.00%) compared to b6b621c Details
β codecov/patch Coverage not affected when comparing b6b621c...28e092e Details
The new version differs by 4 commits .
9cbfa0b
3.10.1
4bb6215
Build: package.json and changelog update for 3.10.1
8a0e92a
Fix: handle try/catch correctly in no-return-await
(fixes #7581) (#7582)
c4dd015
Fix: no-useless-return stack overflow on unreachable loops (fixes #7583) (#7584)
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
As stated in the title, it would be awesome to have an option to also return the route.stack
and have it saved in the returned array list under "middlewares" propriety for each route.
Add badges to the README file
In the README.md
, there is the following definition.
const listEndpoints = require('express-list-endpoints')
It causes linter to fails:
src/app/server.ts
[Error 10,23]: require statement not part of an import statement (no-var-requires)
[Error 10,31]: ' should be " (quotemark)
Opening the issue in case someone else runs into this same issue. Here is how I rewrote the statement.
//const listEndpoints = require('express-list-endpoints')
import * as ListExpressEndpoints from "express-list-endpoints";
// Display endpoints
log(ListExpressEndpoints(express));
Replace the actual build script that versions the changelog for changelog-version
package
Improve the test coverage on the project code.
Function parseEndpoints
has 28 lines of code (exceeds 25 allowed). Consider refactoring.
express-list-endpoints/src/index.js
Line 8 in 0b14cc3
locally i have
var STACK_ITEM_VALID_NAMES = [
'<anonymous>',
'router',
'bound dispatch',
'mounted_app'
]
and this seems to work perfectly. happy to put together a 1 line PR, but wondering if any reason to exclude these? in many apps not allowing app.use(path, router), which results in routes misses a big number of them.
Change the passed arguments to be the app or router instance instead of the stack.
Please check the following example to understand better what I do mean by the title of this issue.
const listEndpoints = require('express-list-endpoints')
const express = require("express");
let app = require('express')();
const userRouter = express.Router();
userRouter.get('/', [function authorize(req,res){}] , function listUsers(req,res){});
userRouter.post('/', [function authorize(req,res){}], function createUser(req,res){});
userRouter.get('/:id', [function authorize(req,res){}] , function getUserById(req,res){});
const teamRouter = express.Router();
teamRouter.get('/', [function authorize(req,res){}] , function listUsers(req,res){});
teamRouter.post('/', [function authorize(req,res){}], function createUser(req,res){});
teamRouter.get('/:id', [function authorize(req,res){}] , function getUserById(req,res){});
app.use('/users', userRouter);
app.use('/teams', teamRouter);
console.log(listEndpoints(app));
The response would be the following:
[
{
path: '/users',
methods: [ 'GET', 'POST' ],
middlewares: [ 'authorize', 'listUsers' ]
},
{
path: '/users/:id',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'getUserById' ]
},
{
path: '/teams',
methods: [ 'GET', 'POST' ],
middlewares: [ 'authorize', 'listUsers' ]
},
{
path: '/teams/:id',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'getUserById' ]
}
]
In the first endpoint, we have the path /users
, with the methods GET
and POST
. That is correct.
Now, the middlewares list is incorrect: we should also have createUser
added in the list.
I would have two suggestions as a possibility:
Thank you for the time for reading this issue, and please leave any comment if you have any questions.
My app contains a lot different endpoints and many are spread within different files.
For this reason, the path on the endpoint is not complete, but the section I'm implementing in that file.
I'm not great at explaining, so here's some examples:
I created an entry point with
app.use(['/auth'], require('./auth/index.js'));
and in that file I have both
router.post('/', async (req, res) => {...})
and router.use('/verify', require('./verifyEmail'));
(which will contain some other endpoints)
meaning that endpoints do not have the complete url they are associated to because the previous bits are defined in the "father" file.
At this point, this is what the script generates:
Note all the methods for the '/' path, those are, in reality, spread across different routes and represent only the final step.
As I said, my explanation could be much better. If you need any further info, don't hesitate to reach out!
Function parseEndpoints
has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Allow these paths:
/route69
/404
/:1arg
/:arg1
Fix readme to reflect the changes on the V2.0.0
Implement Yarn
Try to implement the next regexp
^\/\^\\\/(?:((?:\w|\\\.|-)*)|(\(\?:\(\[\^\\\/\]\+\?\)\)))\\\/.*
To capture the next type of routes:
/^\/v1-0\._0\/?(?=\/|$)/i
Note: Pay attention to the hyphens -
the underscore _
and the dot with the backslash \.
As a user
I want the tool to be able to parse routes like /users/:userId(\d+)
So that I can list this endpoints too
Express Documentation for Route Parameters: https://expressjs.com/en/guide/routing.html#route-parameters
PR: #52
CC: @emirhg
Change eslint config and code to use standar
When attempting to print the routes of a router that has multiple nested routes of arbitrary depth, I get the following (on Express 4.14.x):
TypeError: Cannot read property 'replace' of undefined
at /usr/src/app/node_modules/express-list-endpoints/index.js:40:34
at Array.forEach (native)
at getEndpoints (/usr/src/app/node_modules/express-list-endpoints/index.js:26:9)
at /usr/src/app/node_modules/express-list-endpoints/index.js:49:9
at Array.forEach (native)
at getEndpoints (/usr/src/app/node_modules/express-list-endpoints/index.js:26:9)
...
I believe there is something up with the regex and how it interacts with multi-level nested routes. For reference, my router looks something like this:
const router = express.Router();
router.use( '/top-level-route', require( './sub-route' ) );
sub-route.js
const router = require( 'express' ).Router({ mergeParams: true });
router.use( '/:id/sub-sub-route', require( './sub-sub-route' ) );
router.route( '/' ).post( function( req, res, next ) {
});
module.exports = router;
Function parseEndpoints
has 28 lines of code (exceeds 25 allowed). Consider refactoring.
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.