Open casalot opened 9 years ago
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
}
}
}
}
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'] }}
Well, actually both implementations are very useful. And at plugin level it would be good if we can use regex to express the routes.
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?
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).
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.
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.