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

@gquittet/graceful-server

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gquittet/graceful-server - npm Package Compare versions

Comparing version 2.3.3 to 2.4.0

lib/types/constants/index.d.ts

2

lib/index.js

@@ -1,1 +0,1 @@

(()=>{var e={636:(e,t,s)=>{"use strict";s.d(t,{u:()=>r,Z:()=>i});const n={closePromises:[],timeout:1e3,healthCheck:!0,livenessEndpoint:"/live",readinessEndpoint:"/ready"};let o=!0;const r=e=>(o&&(Object.freeze(Object.assign(n,e)),o=!1),n),i=n},751:(e,t,s)=>{"use strict";s.d(t,{Z:()=>y});const n=require("events"),o=[{type:"SIGHUP",code:1},{type:"SIGBREAK",code:1},{type:"SIGINT",code:2},{type:"SIGTERM",code:15},{type:"uncaughtException",code:2}];var r=s(636),i=s(825);const a=(e,t)=>async(s,n,o)=>{const{timeout:a,closePromises:c}=r.Z,u=o&&o.message?o:new Error(s);var d;t.status.set(i.Z.SHUTTING_DOWN,u),await(d=a,new Promise((e=>setTimeout(e,d)))),await Promise.all(c.map((e=>e()))),await e.stop(),t.status.set(i.Z.SHUTDOWN,u),process.exit(128+n)},c=e=>{const t=e||new Set,s=e=>{e.destroy(),t.delete(e)};return{onConnection:e=>{t.add(e),e.once("close",(()=>t.delete(e)))},closeAll:async()=>t.forEach(s)}},{livenessEndpoint:u,readinessEndpoint:d}=r.Z,l=(e,t)=>{const{healthCheck:s}=r.Z,n=c(),o=c();let i=!1;e.on("connection",n.onConnection),e.on("secureConnection",o.onConnection);const a=e.listeners("request");return e.removeAllListeners("request"),s?(e.on("request",(e=>(t,s)=>{const{livenessEndpoint:n,readinessEndpoint:o}=r.Z;if(!s.headersSent)return t.url===n&&"GET"===t.method?(s.statusCode=200,s.setHeader("Content-Type","application/json"),s.end(JSON.stringify({uptime:0|process.uptime()}))):t.url===o&&"GET"===t.method?e.isReady()?(s.statusCode=200,s.setHeader("Content-Type","application/json"),s.end(JSON.stringify({status:"ready"}))):(s.statusCode=503,s.end()):void 0})(t)),a.forEach((s=>e.on("request",((e,n)=>{if(t.isReady()){if(e.url!==u&&e.url!==d||"GET"!==e.method)return s(e,n)}else e.socket.destroy()}))))):a.forEach((s=>e.on("request",((e,n)=>{if(t.isReady())return s(e,n);e.socket.destroy()})))),Object.assign(e,{stop:async()=>{if(e.listening&&!i)return i=!0,e.removeAllListeners("request"),e.on("request",((e,t)=>{if(!t.headersSent)return t.setHeader("connection","close")})),await Promise.all([n.closeAll(),o.closeAll()]),new Promise(((t,s)=>{e.close((e=>{e?s(e):t()}))}))}})},p=e=>{let t=i.Z.STARTING;return{set:function(s,n){return t=s,e.emit(s,n),this},get:()=>t,setReady:function(){this.set(i.Z.READY)},isReady:()=>t===i.Z.READY}},y=e=>{const t=new n.EventEmitter,s=p(t),r=l(e,s);return{status:s,init:function(){return(e=>{for(const t of o)process.on(t.type,(async s=>{await e.shutdown(t.type,t.code,s)}));return e})(this)},shutdown:function(e,t,s){return a(r,this)(e,t,s)},on:(e,s)=>t.on(e,s)}}},825:(e,t,s)=>{"use strict";var n;s.d(t,{Z:()=>o}),function(e){e.STARTING="STARTING",e.READY="READY",e.SHUTTING_DOWN="SHUTTING_DOWN",e.SHUTDOWN="SHUTDOWN"}(n||(n={}));const o=n},878:()=>{}},t={};function s(n){var o=t[n];if(void 0!==o)return o.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,s),r.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";s.r(n),s.d(n,{default:()=>a});var e=s(636),t=s(751),o=s(825),r=s(878),i={};for(const e in r)"default"!==e&&(i[e]=()=>r[e]);s.d(n,i);const a=Object.assign(((s,n)=>{(0,e.u)(n);const o=(0,t.Z)(s).init();return{isReady:()=>o.status.isReady(),setReady:()=>o.status.setReady(),on:o.on}}),o.Z)})(),module.exports=n})();const __export__=module.exports;module.exports=__export__.default,Object.assign(module.exports,__export__);
(()=>{var e={636:(e,t,s)=>{"use strict";s.d(t,{u:()=>r,Z:()=>i});const o={closePromises:[],timeout:1e3,healthCheck:!0,livenessEndpoint:"/live",readinessEndpoint:"/ready",gracePeriod:0};let n=!0;const r=e=>(n&&(Object.freeze(Object.assign(o,e)),n=!1),o),i=o},31:(e,t,s)=>{"use strict";s.d(t,{Z:()=>y});const o=require("events"),n=[{type:"SIGHUP",code:1},{type:"SIGBREAK",code:1},{type:"SIGINT",code:2},{type:"SIGTERM",code:15},{type:"uncaughtException",code:2}];var r=s(636),i=s(825);const a=e=>new Promise((t=>setTimeout(t,e))),c=e=>{const t=e||new Set,s=e=>{e.destroy(),t.delete(e)};return{onConnection:e=>{t.add(e),e.once("close",(()=>t.delete(e)))},closeAll:async()=>t.forEach(s)}},{livenessEndpoint:d,readinessEndpoint:u}=r.Z,l=(e,t)=>{const{healthCheck:s}=r.Z,o=c(),n=c();let i=!1;e.on("connection",o.onConnection),e.on("secureConnection",n.onConnection);const a=e.listeners("request");return e.removeAllListeners("request"),s?(e.on("request",(e=>(t,s)=>{const{livenessEndpoint:o,readinessEndpoint:n}=r.Z;if(!s.headersSent)return t.url===o&&"GET"===t.method?(s.statusCode=200,s.setHeader("Content-Type","application/json"),s.end(JSON.stringify({uptime:0|process.uptime()}))):t.url===n&&"GET"===t.method?e.isReady()?(s.statusCode=200,s.setHeader("Content-Type","application/json"),s.end(JSON.stringify({status:"ready"}))):(s.statusCode=503,s.end()):void 0})(t)),a.forEach((s=>e.on("request",((e,o)=>{if(t.isReady()){if(e.url!==d&&e.url!==u||"GET"!==e.method)return s(e,o)}else e.socket.destroy()}))))):a.forEach((s=>e.on("request",((e,o)=>{if(t.isReady())return s(e,o);e.socket.destroy()})))),Object.assign(e,{stop:async()=>{if(e.listening&&!i)return i=!0,e.removeAllListeners("request"),e.on("request",((e,t)=>{if(!t.headersSent)return t.setHeader("connection","close")})),await Promise.all([o.closeAll(),n.closeAll()]),new Promise(((t,s)=>{e.close((e=>{e?s(e):t()}))}))}})},p=e=>{let t=i.Z.STARTING;return{set:function(s,o){return t=s,e.emit(s,o),this},get:()=>t,setReady:function(){this.set(i.Z.READY)},isReady:()=>t===i.Z.READY}},y=e=>{const t=new o.EventEmitter,s=p(t),c=l(e,s);return{status:s,init:function(){return(e=>{for(const t of n)process.on(t.type,(async s=>{await e.shutdown(t.type,t.code,s)}));return e})(this)},shutdown:function(e,t,s){return((e,t)=>async(s,o,n)=>{const{timeout:c,closePromises:d,gracePeriod:u}=r.Z,l=n&&n.message?n:new Error(s);u>0&&await a(1e3*u),t.status.set(i.Z.SHUTTING_DOWN,l),await a(c),await Promise.all(d.map((e=>e()))),await e.stop(),t.status.set(i.Z.SHUTDOWN,l),process.exit(128+o)})(c,this)(e,t,s)},on:(e,s)=>t.on(e,s)}}},825:(e,t,s)=>{"use strict";var o;s.d(t,{Z:()=>n}),function(e){e.STARTING="STARTING",e.READY="READY",e.SHUTTING_DOWN="SHUTTING_DOWN",e.SHUTDOWN="SHUTDOWN"}(o||(o={}));const n=o},878:()=>{}},t={};function s(o){var n=t[o];if(void 0!==n)return n.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,s),r.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var o in t)s.o(t,o)&&!s.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{"use strict";s.r(o),s.d(o,{default:()=>a});var e=s(636),t=s(31),n=s(825),r=s(878),i={};for(const e in r)"default"!==e&&(i[e]=()=>r[e]);s.d(o,i);const a=Object.assign(((s,o)=>{(0,e.u)(o);const n=(0,t.Z)(s).init();return{isReady:()=>n.status.isReady(),setReady:()=>n.status.setReady(),on:n.on}}),n.Z)})(),module.exports=o})();const __export__=module.exports;module.exports=__export__.default,Object.assign(module.exports,__export__);

@@ -7,2 +7,3 @@ export default interface IOptions {

readinessEndpoint: string;
gracePeriod: number;
}

@@ -15,3 +15,3 @@ {

},
"version": "2.3.3",
"version": "2.4.0",
"main": "./lib/index.js",

@@ -18,0 +18,0 @@ "scripts": {

@@ -309,9 +309,10 @@ <h1 align="center">

| Name | Type | Default | Description |
| ----------------- | :------------------------: | :-----: | ---------------------------------------------------------------: |
| closePromises | (() => Promise<unknown>)[] | [] | The functions to run when the API is stopping |
| timeout | number | 1000 | The time in milliseconds to wait before shutting down the server |
| healthCheck | boolean | true | Enable/Disable the default endpoints (liveness and readiness) |
| livenessEndpoint | string | /live | The liveness endpoint |
| readinessEndpoint | string | /ready | The readiness endpoint |
| Name | Type | Default | Description |
| ----------------- | :------------------------: | :-----: | -----------------------------------------------------------------------: |
| closePromises | (() => Promise<unknown>)[] | [] | The functions to run when the API is stopping |
| timeout | number | 1000 | The time in milliseconds to wait before shutting down the server |
| healthCheck | boolean | true | Enable/Disable the default endpoints (liveness and readiness) |
| livenessEndpoint | string | /live | The liveness endpoint |
| readinessEndpoint | string | /ready | The readiness endpoint |
| gracePeriod | number | 0 | Number of seconds to wait before stopping to accept the incoming traffic |

@@ -438,2 +439,5 @@ ### GracefulServer Instance

In the following example, you have to setup the gracePeriod to 5 seconds because you set up the readiness timeout to 5 seconds.
[(Related to this issue)](https://github.com/gquittet/graceful-server/issues/5)
```yml

@@ -440,0 +444,0 @@ readinessProbe:

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