From e2e6cba3ad9afbf755abeffb4dce0b8f08f4f207 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Fri, 10 Jul 2020 16:11:48 +0100 Subject: [PATCH 1/2] feat(extendRouter): add config to allow to extend router, since middleware doesn't has access to res/next object --- deploy_docs.sh | 5 +---- docs/configuration.md | 3 +++ lib/server_middleware/api.js | 5 +++++ tests/api.extend.router.test.js | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tests/api.extend.router.test.js diff --git a/deploy_docs.sh b/deploy_docs.sh index 0dc3ac8..810e978 100755 --- a/deploy_docs.sh +++ b/deploy_docs.sh @@ -1,11 +1,10 @@ #!/usr/bin/env sh # abort on errors -set -e +#set -e GIT_NAME=$(git config --get user.name) GIT_EMAIL=$(git config --get user.email) -GIT_SSH_COMMAND=$(git config --get core.sshCommand) # build yarn docs:build @@ -17,8 +16,6 @@ git init git config user.name "$GIT_NAME" git config user.email "$GIT_EMAIL" -git config core.sshCommand "$GIT_SSH_COMMAND" - git add -A git commit -m 'Updated documentation' git push -f git@github.com:ezypeeze/nuxt-neo.git master:gh-pages diff --git a/docs/configuration.md b/docs/configuration.md index 998cf54..393f984 100755 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -22,6 +22,9 @@ The default options are: // If controller action return is null/empty, return 204 No Content noContentStatusOnEmpty: true, + + // Allows you to extend express router before going to request middleware + extendRouter: null, // Middleware handlers for all your api. middleware: [], diff --git a/lib/server_middleware/api.js b/lib/server_middleware/api.js index 74a0014..2c91a44 100755 --- a/lib/server_middleware/api.js +++ b/lib/server_middleware/api.js @@ -134,6 +134,11 @@ function injectAPI(options) { // Request body parsers router.use(...(injectBodyParsers(options))); + // Extend router + if (typeof options.extendRouter === "function") { + options.extendRouter(router); + } + // Middleware for all API routes if (options.middleware) { router.use(function (req, res, next) { diff --git a/tests/api.extend.router.test.js b/tests/api.extend.router.test.js new file mode 100644 index 0000000..d71a8c3 --- /dev/null +++ b/tests/api.extend.router.test.js @@ -0,0 +1,24 @@ +const test = require('ava'); +const qs = require('querystring'); + +/* global globalBeforeAll:readable, globalAfterAll:readable, api:readable */ + +test.before(globalBeforeAll({ + moduleOptions: { + extendRouter: (router) => { + router.use(function (req, res) { + res.send('NOTHING GOES BEYOUND THIS'); + }); + } + } +})); +test.after(globalAfterAll()); + +test('Test extend router function', async (t) => { + const { data } = await api.post('/users', { + first_name: 'nuxt', + last_name: 'neo' + }); + + t.is(data, 'NOTHING GOES BEYOUND THIS'); +}); \ No newline at end of file From 115f8e4d2895dcda51d5e17edde180319ca30e4d Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Fri, 10 Jul 2020 16:13:59 +0100 Subject: [PATCH 2/2] chore(release): 4.2.0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b9830f..3a7da21 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [4.2.0](https://github.com/ezypeeze/nuxt-neo/compare/v4.1.0...v4.2.0) (2020-07-10) + + +### Features + +* **extendRouter:** add config to allow to extend router, since middleware doesn't has access to res/next object ([e2e6cba](https://github.com/ezypeeze/nuxt-neo/commit/e2e6cba3ad9afbf755abeffb4dce0b8f08f4f207)) + ## [4.1.0](https://github.com/ezypeeze/nuxt-neo/compare/v4.0.0...v4.1.0) (2020-06-30) ### Features diff --git a/package.json b/package.json index daddc36..2076e24 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-neo", - "version": "4.1.0", + "version": "4.2.0", "description": "A nuxt.js module that implements a universal api layer, same-way compatible between server and client side.", "keywords": [ "nuxt",