Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to exclude certain routes #20

Open
casalot opened this issue Oct 15, 2015 · 6 comments
Open

Ability to exclude certain routes #20

casalot opened this issue Oct 15, 2015 · 6 comments
Milestone

Comments

@casalot
Copy link

casalot commented Oct 15, 2015

Could you perhaps add an option to the option to exclude certain routes? I'm using the hapi-swagger plugin, and now blipp shows the /docs and /documentation routes in the route table.

@danielb2 danielb2 added this to the 2.3.1 milestone Oct 15, 2015
@tomas-campodonico
Copy link

I came up with a simple solution to allow this functionality. @danielb2 please let me know if you like it and if you are going to implement it as I need it on my project. I'll paste here the modified code. Thanks

internals.connectionInfo = function (routes, options, connectionInfo) {

    for (var i = 0, il = routes.length; i < il; ++i) {
        var route = routes[i];

        if (!route.settings.plugins.blipp || !route.settings.plugins.blipp.excluded) {

            var defaultStrategy = Hoek.reach(route, 'connection.auth.settings.default.strategies');
            var authStrategy = route.settings.auth ? route.settings.auth.strategies.toString() : false;

            if (route.settings.auth === undefined) {
                authStrategy = defaultStrategy ? String(defaultStrategy) : false;
            }

            var show = {
                method: route.method.toUpperCase(),
                path: route.path,
                description: route.settings.description || ''
            };

            if (options.showAuth) {
                show.auth = authStrategy;
            };

            connectionInfo.routes.push(show);
        }
    }

    connectionInfo.routes.sort(function (a, b) {

        return a.path.localeCompare(b.path);
    });
};

Now, you can simply add in the config object of your route the option to exclude that route. i.e

{
      path: '/doc/category',
      method: 'POST',
      handler: (req, reply) => {
        reply('OK');
      },
      config: {
        description: 'Add new category',
        tags: ['api'],
        plugins: {
          blipp: {
            excluded: true
          }
        }
      }
    }

@danielb2
Copy link
Owner

would it be easier to just have a list of paths in the plugin registration of what to exclude? Or is on a per-route basis better? Seems like more work to do it per route:

{ register: Blipp, options: { exclude: ['/docs', '/documentation'] }}

@tomas-campodonico
Copy link

Well, actually both implementations are very useful. And at plugin level it would be good if we can use regex to express the routes.

@danielb2
Copy link
Owner

What's the problem with having /docs and /documentations show up when they do exist?

IOW, what's the use-case for hiding routes that do exist?

@tomas-campodonico
Copy link

Sometimes you may have some routes for testing purpose or, in the case of hapi-swagger, a lot of routes for documentation. If your API has a lot of endpoints and each endpoint has its documentation route, then you end up with lot of endpoints your API doesn't export (as I said, they are just for internal use only).

@danielb2
Copy link
Owner

How are you blocking off the endpoints which are for internal use only then? If they're on a different connection, blipp will show it as being on the other connection.

btw, I've already implemented the code in the exclude branch, I'm just having second thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants