Skip to content

Add excluded option #39

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.tgz
yarn.lock
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ See [examples](examples/) for examples

The following options are available:

* `showAuth`: Shows any hapi authentication scheme using _server.auth.strategy_. Default: false
* `showScope`: Shows route access rules using _route.options.auth.access.scope_. Default: false
* `showStart`: Shows route information during startup of server. Default: true
Option | Type | Description | Defaut
-|:-:|:-:|-
`showAuth` | boolean | Shows any hapi authentication scheme using _server.auth.strategy_ | `false`
`showScope` | boolean | Shows route access rules using _route.options.auth.access.scope_ | `false`
`showStart` | boolean | Shows route information during startup of server | `true`
`exclude` | array | Doesn't show specified routes. Routes should be a `string` type. Example, [`'/doc'`, `'/swagger'`] | `[ ]`


The module also registers the _'info()'_ and _'text()'_ API methods:
Expand Down
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const internals = {
schema: {
showAuth: Joi.boolean().default(false),
showScope: Joi.boolean().default(false),
showStart: Joi.boolean().default(true)
showStart: Joi.boolean().default(true),
exclude: Joi.array().items(Joi.string().regex(/\/[a-zA-Z0-9.-]*/)).default([])
}
};

Expand Down Expand Up @@ -70,6 +71,10 @@ internals.printableRoutes = function (routes, options) {

routes.forEach((show) => {

if (options.exclude.includes(show.path)){
return;
}

const row = {
method: internals.formatMethod(show.method),
path: internals.formatPath(show.path),
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ describe('routes', () => {
expect(text).to.match(/findme.*api routes/);
});

it('exclude routes should be shown', async () => {

const blippOptions = {
exclude: [
'/api',
'/hi'
]
};

const server = await internals.prepareServer({ blippOptions });

const info = server.plugins[Pkg.name].info();
delete info[0].uri;
const text = server.plugins[Pkg.name].text();
expect(text).to.not.match(/\/api/);
expect(text).to.not.match(/\/hi/);
});

it('fails with invalid options', async () => {

try {
Expand Down