Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-healthcheck

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-healthcheck - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

10

CHANGELOG.md
# Change Log
## [4.2.0](https://github.com/smartiniOnGitHub/fastify-healthcheck/releases/tag/4.2.0) (2022-09-01)
[Full Changelog](https://github.com/smartiniOnGitHub/fastify-healthcheck/compare/4.1.0...4.2.0)
Summary Changelog:
- Updated requirements to Fastify '^4.5.3' and under-pressure '^8.1.0'
- Compatibility with TypeScript 4.8
- Improve plugin source docs, with JSDoc
- Simplified/updated plugin tests
## [4.1.0](https://github.com/smartiniOnGitHub/fastify-healthcheck/releases/tag/4.1.0) (2022-07-19)
[Full Changelog](https://github.com/smartiniOnGitHub/fastify-healthcheck/compare/4.0.0...4.1.0)
Summary Changelog:
- Updated requirements to Fastify '^4.0.1' and Fastify-plugin '^4.0.0'
- Updated requirements to Fastify '^4.0.1'
- Ensure all is good as before

@@ -8,0 +16,0 @@

4

example/example-under-pressure-fail.js

@@ -35,5 +35,5 @@ /*

fastify.get('/', function (req, reply) {
const path = require('path')
const path = require('node:path')
const scriptRelativeFolder = path.join(__dirname, path.sep)
const fs = require('fs')
const fs = require('node:fs')
const stream = fs.createReadStream(path.join(scriptRelativeFolder, 'home.html'))

@@ -40,0 +40,0 @@ reply.type('text/html; charset=utf-8').send(stream)

@@ -32,5 +32,5 @@ /*

fastify.get('/', function (req, reply) {
const path = require('path')
const path = require('node:path')
const scriptRelativeFolder = path.join(__dirname, path.sep)
const fs = require('fs')
const fs = require('node:fs')
const stream = fs.createReadStream(path.join(scriptRelativeFolder, 'home.html'))

@@ -37,0 +37,0 @@ reply.type('text/html; charset=utf-8').send(stream)

{
"name": "fastify-healthcheck",
"version": "4.1.0",
"version": "4.2.0",
"description": "Fastify Plugin to serve responses for health checks",

@@ -8,2 +8,4 @@ "main": "src/plugin",

"scripts": {
"audit:log": "npm audit > ./temp/audit.log",
"clean:install": "rm -rf ./package-lock.json ./node_modules/",
"dependency:log": "npm list > ./temp/dependencies.log",

@@ -40,15 +42,14 @@ "docker:build:fail": "docker build -t fastify-healthcheck-example -f Dockerfile-fail.example .",

"dependencies": {
"@fastify/under-pressure": "^7.0.0"
"@fastify/under-pressure": "^8.1.0"
},
"devDependencies": {
"@types/node": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"fastify": "^4.0.1",
"jsdoc": "^3.6.10",
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"fastify": "^4.5.3",
"jsdoc": "^3.6.11",
"simple-get": "^4.0.1",
"standard": "^17.0.0",
"tap": "^16.3.0",
"tsd": "^0.22.0",
"typescript": "^4.7.4"
"tsd": "^0.23.0"
},

@@ -55,0 +56,0 @@ "standard": {

@@ -26,2 +26,3 @@ # fastify-healthcheck

- `exposeUptime`, to return even Node.js process uptime (by default disabled)
- `underPressureOptions`, for options to send directly to under-pressure

@@ -31,3 +32,3 @@ Under the hood, the healthcheck status is determined by the

used here as a dependency; so it's possible to specify all its
configuration options here.
configuration options in related option.

@@ -90,3 +91,3 @@ To use all default values for `healthcheck` options, do not set its options

Fastify ^4.0.1 , Node.js 14 LTS (14.15.0) or later.
Fastify ^4.5.3 , Node.js 14 LTS (14.15.0) or later.
Note that plugin releases 3.x are for Fastify 3.x, 4.x are for Fastify 4.x, etc.

@@ -93,0 +94,0 @@

@@ -24,3 +24,3 @@ /*

// even to avoid dependencies clash
const http = require('http')
const http = require('node:http')

@@ -27,0 +27,0 @@ const options = {

@@ -18,6 +18,28 @@ /*

/**
* Plugin:
* this module exports the plugin as a function.
* @module plugin
*/
const payloadOK = { statusCode: 200, status: 'ok' }
const payloadKO = { statusCode: 500, status: 'ko' }
function fastifyHealthcheck (fastify, options, next) {
/**
* Plugin implementation.
*
* @param {!object} fastify Fastify instance
* @param {!object} options plugin configuration options
* <ul>
* <li>healthcheckUrl (string, default `/health`) for the route of the health check,</li>
* <li>healthcheckUrlDisable (boolean, default false) flag to disable health check route,</li>
* <li>healthcheckUrlAlwaysFail (boolean, default false) flag to always return failure from health check route (mainly for testing purposes),</li>
* <li>exposeUptime (boolean, default false) flag to show even process uptime in health check results,</li>
* <li>underPressureOptions (object, default empty) for options to send directly to under-pressure,</li>
* </ul>
* @param {!function} done callback, to call as last step
*
* @namespace
*/
function fastifyHealthcheck (fastify, options, done) {
const {

@@ -61,5 +83,13 @@ healthcheckUrl = '/health',

next()
done()
}
/**
* Handler that generates a failure response.
*
* @param {!req} req the request
* @param {!reply} reply the response
*
* @private
*/
function failHandler (req, reply) {

@@ -69,2 +99,10 @@ reply.code(500).send(payloadKO)

/**
* Handler that generates a success response.
*
* @param {!req} req the request
* @param {!reply} reply the response
*
* @private
*/
function normalHandler (req, reply) {

@@ -74,2 +112,10 @@ reply.code(200).send(payloadOK)

/**
* Handler that generates a success response, and show even process uptime.
*
* @param {!req} req the request
* @param {!reply} reply the response
*
* @private
*/
function normalHandlerWithUptime (req, reply) {

@@ -79,2 +125,4 @@ reply.code(200).send({ ...payloadOK, uptime: process.uptime() })

// utility functions
function ensureIsString (arg, name) {

@@ -81,0 +129,0 @@ if (arg !== null && typeof arg !== 'string') {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc