From 324ebf308f13594c086ec932eaa5b44e0a09ecad Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Mon, 13 Dec 2021 15:02:30 +0100 Subject: [PATCH 1/6] feat: add @vue-storefront/health-check module --- packages/core/docs/changelog/6541.js | 2 +- packages/core/health-check/.gitignore | 2 ++ packages/core/health-check/lib/module.js | 9 ++++++++ packages/core/health-check/package.json | 22 +++++++++++++++++++ packages/core/nuxt-module/lib/module.js | 7 ------ .../nuxt-module/lib/plugins/health-check.js | 8 ------- 6 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 packages/core/health-check/.gitignore create mode 100644 packages/core/health-check/lib/module.js create mode 100644 packages/core/health-check/package.json delete mode 100644 packages/core/nuxt-module/lib/plugins/health-check.js diff --git a/packages/core/docs/changelog/6541.js b/packages/core/docs/changelog/6541.js index bd57a733f0..417d0fd176 100644 --- a/packages/core/docs/changelog/6541.js +++ b/packages/core/docs/changelog/6541.js @@ -1,5 +1,5 @@ module.exports = { - description: 'Add health check under /healthz', + description: 'Add `@vue-storefront/health-check` module ', link: 'https://github.com/vuestorefront/vue-storefront/issues/6541', isBreaking: false, breakingChanges: [], diff --git a/packages/core/health-check/.gitignore b/packages/core/health-check/.gitignore new file mode 100644 index 0000000000..c434d59719 --- /dev/null +++ b/packages/core/health-check/.gitignore @@ -0,0 +1,2 @@ +node_modules +!lib diff --git a/packages/core/health-check/lib/module.js b/packages/core/health-check/lib/module.js new file mode 100644 index 0000000000..5ab80290b3 --- /dev/null +++ b/packages/core/health-check/lib/module.js @@ -0,0 +1,9 @@ +function handler (req, res, next) { + res.end('ok') +}; + +module.exports = function healthCheckModule() { + const serverMiddleware = { path: '/healthz', handler }; + + this.addServerMiddleware(serverMiddleware); +}; diff --git a/packages/core/health-check/package.json b/packages/core/health-check/package.json new file mode 100644 index 0000000000..bff5c9907f --- /dev/null +++ b/packages/core/health-check/package.json @@ -0,0 +1,22 @@ +{ + "name": "@vue-storefront/health-check", + "version": "1.0.0", + "description": "", + "main": "lib/module.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Vue Storefront", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuestorefront/vue-storefront.git" + }, + "bugs": { + "url": "https://github.com/vuestorefront/vue-storefront/issues" + }, + "homepage": "https://github.com/vuestorefront/vue-storefront#readme" +} diff --git a/packages/core/nuxt-module/lib/module.js b/packages/core/nuxt-module/lib/module.js index 102f23dcec..bdb0989e8d 100644 --- a/packages/core/nuxt-module/lib/module.js +++ b/packages/core/nuxt-module/lib/module.js @@ -50,13 +50,6 @@ module.exports = function VueStorefrontNuxtModule (moduleOptions) { }); } - // Health Check plugin - this.options.router.middleware.push('health-check') - this.addPlugin({ - src: path.resolve(__dirname, 'plugins/health-check.js') - }) - log.success('Installed Vue Storefront Health Check plugin'); - // Context plugin this.addPlugin(path.resolve(__dirname, 'plugins/context.js')) log.success('Installed Vue Storefront Context plugin'); diff --git a/packages/core/nuxt-module/lib/plugins/health-check.js b/packages/core/nuxt-module/lib/plugins/health-check.js deleted file mode 100644 index f8c4cdc7ce..0000000000 --- a/packages/core/nuxt-module/lib/plugins/health-check.js +++ /dev/null @@ -1,8 +0,0 @@ -import Middleware from './middleware' - -Middleware['health-check'] = function ({ app, res }) { - const currentPath = app.context.route.fullPath; - if (currentPath === '/healthz') { - res.end('ok'); - } -}; From ba2d95bb90b249051209df15aa9448104308c945 Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Mon, 13 Dec 2021 15:38:37 +0100 Subject: [PATCH 2/6] chore: cr fix --- packages/core/health-check/lib/module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/health-check/lib/module.js b/packages/core/health-check/lib/module.js index 5ab80290b3..ddfc8b3c2f 100644 --- a/packages/core/health-check/lib/module.js +++ b/packages/core/health-check/lib/module.js @@ -1,4 +1,4 @@ -function handler (req, res, next) { +function handler (req, res) { res.end('ok') }; From 78999ced32319af7b1b0de5e0fb1d90a4767a5e8 Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Mon, 13 Dec 2021 15:41:24 +0100 Subject: [PATCH 3/6] chore: add Readme --- packages/core/health-check/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/core/health-check/README.md diff --git a/packages/core/health-check/README.md b/packages/core/health-check/README.md new file mode 100644 index 0000000000..304f47430d --- /dev/null +++ b/packages/core/health-check/README.md @@ -0,0 +1,14 @@ +# VSF Health Check + +## Setup + +### Add `@vue-storefront/health-check` module to nuxt.config.js + +```js +module.exports = { + // ..., + '@vue-storefront/health-check' +} +``` + +Health Check is available under `/healthz` endpoint. From aa65f7945628788b868a67402d22d5b685bf685e Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Mon, 13 Dec 2021 16:05:12 +0100 Subject: [PATCH 4/6] chore: fix readme --- packages/core/health-check/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/health-check/README.md b/packages/core/health-check/README.md index 304f47430d..9084faa2cf 100644 --- a/packages/core/health-check/README.md +++ b/packages/core/health-check/README.md @@ -7,7 +7,9 @@ ```js module.exports = { // ..., - '@vue-storefront/health-check' + modules: [ + '@vue-storefront/health-check' + ] } ``` From e4bfbb669abce5d530fe4c79f7e354fe38b2ef78 Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Mon, 13 Dec 2021 16:28:08 +0100 Subject: [PATCH 5/6] chore: fix readme --- packages/core/health-check/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/core/health-check/README.md b/packages/core/health-check/README.md index 9084faa2cf..3f0cbea9b2 100644 --- a/packages/core/health-check/README.md +++ b/packages/core/health-check/README.md @@ -2,6 +2,14 @@ ## Setup +### Install with yarn: + +`yarn add @vue-storefront/health-check` + +### Install with npm: + +`npm install @vue-storefront/health-check` + ### Add `@vue-storefront/health-check` module to nuxt.config.js ```js From 1170baa1a1c903200319de42dfbf1966ba0e14be Mon Sep 17 00:00:00 2001 From: ljedrasik Date: Tue, 14 Dec 2021 08:21:07 +0100 Subject: [PATCH 6/6] chore: fix readme --- packages/core/health-check/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/health-check/README.md b/packages/core/health-check/README.md index 3f0cbea9b2..a1a0038ce5 100644 --- a/packages/core/health-check/README.md +++ b/packages/core/health-check/README.md @@ -14,7 +14,6 @@ ```js module.exports = { - // ..., modules: [ '@vue-storefront/health-check' ]