From 3dda954f763341d7285e696b0c93ee20849b19c5 Mon Sep 17 00:00:00 2001 From: Michael Berkowski Date: Wed, 21 May 2025 16:47:05 -0500 Subject: [PATCH 1/2] healthcheck 200 response endpoint --- README.md | 16 +++++++++++++--- index.js | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ba2db3a..9ca1f81 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ http://primo.lib.umn.edu/primo_library/libweb/action/dlSearch.do?institution=TWI - [Sessions](#sessions) - [Logging](#logging) - [redirectLogEvent(ctx)](#redirectlogeventctx) +- [Health Check URI](#health-check-uri) - [Install](#install) - [Test](#test) - [Lint](#lint) @@ -220,7 +221,7 @@ Janus uses [koa-session](https://www.npmjs.com/package/koa-session) to assign ea One way to override this method when invoking Janus: -```javascript +```javascript const plugins = require('your-plugins'); const janus = require('@nihiliad/janus').methods({ sessionId (ctx) { @@ -229,7 +230,7 @@ const janus = require('@nihiliad/janus').methods({ // generate your session id ); }); - }, + }, }); const app = janus({ uriFactoryPlugins: plugins, @@ -264,6 +265,15 @@ const app = janus({ app.listen(3000); ``` +## Health Check URI +The application will return a basic `200 ok` at a URI under `uriPathPrefix`, e.g. +``` +// uriPathPrefix = '/janus' + +GET /janus/healthcheck +200 ok +``` + ## Install Install with npm. In package.json, include something like... @@ -272,7 +282,7 @@ Install with npm. In package.json, include something like... "dependencies": { "@nihiliad/janus": "^2.0.0" } -``` +```` ...where version based on the `version` value in this project's `package.json`. Then `npm install`. diff --git a/index.js b/index.js index 821e1ba..b68a945 100644 --- a/index.js +++ b/index.js @@ -98,6 +98,12 @@ export default stampit() } }) + // Basic 200 response to validate the node app works + // No logging redirect/error + router.get(params.uriPathPrefix + '/healthcheck', function(ctx, next) { + ctx.body = 'ok' + }) + const app = new Koa() app .use(favicon(this.favicon)) From 05acbbe6bf7fe79696a3a7a3e1285c4be794fe68 Mon Sep 17 00:00:00 2001 From: Michael Berkowski Date: Wed, 21 May 2025 16:57:12 -0500 Subject: [PATCH 2/2] bad readme markdown --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ca1f81..a58fe07 100644 --- a/README.md +++ b/README.md @@ -282,7 +282,7 @@ Install with npm. In package.json, include something like... "dependencies": { "@nihiliad/janus": "^2.0.0" } -```` +``` ...where version based on the `version` value in this project's `package.json`. Then `npm install`.