From e4edbc57a06e42618229912b02b50459eb9b8c77 Mon Sep 17 00:00:00 2001 From: Mosiura Maksym Date: Sat, 20 Oct 2018 03:36:37 +0300 Subject: [PATCH 1/2] Add excluded option --- .gitignore | 1 + README.md | 9 ++++++--- lib/index.js | 7 ++++++- test/index.js | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9e406a5..1adaa15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules *.tgz +yarn.lock \ No newline at end of file diff --git a/README.md b/README.md index 90da32d..2a5d241 100644 --- a/README.md +++ b/README.md @@ -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` +`excluded` | 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: diff --git a/lib/index.js b/lib/index.js index 651f943..74054fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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), + excluded: Joi.array().items(Joi.string().regex(/\/[a-zA-Z0-9.-]*/)).default([]) } }; @@ -70,6 +71,10 @@ internals.printableRoutes = function (routes, options) { routes.forEach((show) => { + if (options.excluded.includes(show.path)){ + return; + } + const row = { method: internals.formatMethod(show.method), path: internals.formatPath(show.path), diff --git a/test/index.js b/test/index.js index e547e9b..6109c3c 100644 --- a/test/index.js +++ b/test/index.js @@ -282,6 +282,24 @@ describe('routes', () => { expect(text).to.match(/findme.*api routes/); }); + it('excluded routes should be shown', async () => { + + const blippOptions = { + excluded: [ + '/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 { From d88149e6eb50d09d88ecb14fda2be1d23696bc63 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Nov 2018 19:56:26 +0200 Subject: [PATCH 2/2] replace excluded to exclude --- README.md | 2 +- lib/index.js | 4 ++-- test/index.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2a5d241..62c412f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ 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` -`excluded` | array | Doesn't show specified routes. Routes should be a `string` type. Example, [`'/doc'`, `'/swagger'`] | `[ ]` +`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: diff --git a/lib/index.js b/lib/index.js index 74054fe..7ca883d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,7 +14,7 @@ const internals = { showAuth: Joi.boolean().default(false), showScope: Joi.boolean().default(false), showStart: Joi.boolean().default(true), - excluded: Joi.array().items(Joi.string().regex(/\/[a-zA-Z0-9.-]*/)).default([]) + exclude: Joi.array().items(Joi.string().regex(/\/[a-zA-Z0-9.-]*/)).default([]) } }; @@ -71,7 +71,7 @@ internals.printableRoutes = function (routes, options) { routes.forEach((show) => { - if (options.excluded.includes(show.path)){ + if (options.exclude.includes(show.path)){ return; } diff --git a/test/index.js b/test/index.js index 6109c3c..e580790 100644 --- a/test/index.js +++ b/test/index.js @@ -282,10 +282,10 @@ describe('routes', () => { expect(text).to.match(/findme.*api routes/); }); - it('excluded routes should be shown', async () => { + it('exclude routes should be shown', async () => { const blippOptions = { - excluded: [ + exclude: [ '/api', '/hi' ]