Giter VIP home page Giter VIP logo

express-list-endpoints's People

Contributors

albertofdzm avatar dependabot[bot] avatar greenkeeper[bot] avatar nwalters512 avatar rdougan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

express-list-endpoints's Issues

Express Router: Separated Path Methods

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' ] } ]

Great util! Thx

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!

incorrect path depth

The 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.

An in-range update of eslint-plugin-standard is breaking the build 🚨

Version 2.2.0 of eslint-plugin-standard just got published.

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 πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 3 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Feature Request : Route title and description.

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.

Can't enumerate asyncRouter endpoints

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?

An in-range update of eslint is breaking the build 🚨

Version 3.10.1 of eslint just got published.

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 πŸ’ͺ


Status Details
  • ❌ 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

Release Notes v3.10.1
  • 8a0e92a Fix: handle try/catch correctly in no-return-await (fixes #7581) (#7582) (Teddy Katz)
  • c4dd015 Fix: no-useless-return stack overflow on unreachable loops (fixes #7583) (#7584) (Teddy Katz)
Commits

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.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

require statement not part of an import statement

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));

allow <anonymous> in STACK_ITEM_VALID_NAMES

var STACK_ITEM_VALID_NAMES = [

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.

express.Router with with two methods on one path does not display middleswares list correctly

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:

  1. To have one endpoint in the list for each method (paths would be duplicated then)
  2. The list of middlewares should be associated/mapped with the method that it is associated

Thank you for the time for reading this issue, and please leave any comment if you have any questions.

Not generating full path of endpoints

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:
image
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!

Fix readme

Fix readme to reflect the changes on the V2.0.0

Improves regexp for routes

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 \.

"Cannot read property 'replace' of undefined" with multiple nested routes

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.