@gquittet/graceful-server
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=require("events")},function(e,t,n){"use strict";n.r(t);const o={closePromises:[],timeout:1e3,livenessEndpoint:"/live",readinessEndpoint:"/ready"};let r=!0;var s=o;var i=[{type:"SIGHUP",code:1},{type:"SIGBREAK",code:1},{type:"SIGINT",code:2},{type:"SIGTERM",code:15},{type:"uncaughtException",code:2}];var a,u=e=>{for(const t of i)process.on(t.type,async n=>{await e.shutdown(t.type,t.code,n)});return e};!function(e){e.NOT_READY="NOT_READY",e.READY="READY",e.SHUTDOWN="SHUTDOWN",e.SHUTTING_DOWN="SHUTTING_DOWN"}(a||(a={}));var c=a;var d=e=>new Promise(t=>setTimeout(t,e));var l=(e,t)=>async(n,o,r)=>{const{timeout:i,closePromises:a}=s,u=r&&r.message?r:new Error(n);t.status.set(c.SHUTTING_DOWN,u),await d(i),await Promise.all(a.map(e=>e())),await e.stop(),t.status.set(c.SHUTDOWN,u),process.exit(128+o)},f=n(0);var p=e=>(t,n)=>{const{livenessEndpoint:o,readinessEndpoint:r}=s;if(!n.headersSent)return t.url===o&&"GET"===t.method?(n.statusCode=200,n.setHeader("Content-Type","application/json"),n.end(JSON.stringify({uptime:0|process.uptime()}))):t.url===r&&"GET"===t.method?e.isReady()?(n.statusCode=200,n.setHeader("Content-Type","application/json"),n.end(JSON.stringify({status:"ready"}))):(n.statusCode=503,n.end()):void 0};var y=e=>{const t=e||new Set,n=e=>{e.destroy(),t.delete(e)};return{onConnection:e=>{t.add(e),e.once("close",()=>t.delete(e))},closeAll:async()=>t.forEach(n)}};var v=(e,t)=>{const n=y(),o=y();let r=!1;e.on("connection",n.onConnection),e.on("secureConnection",o.onConnection);const s=e.listeners("request");e.removeAllListeners("request"),e.on("request",p(t)),s.forEach(n=>e.on("request",(e,o)=>{t.isReady()?n(e,o):e.socket.destroy()}));return Object.assign(e,{stop:async()=>{if(e.listening&&!r)return r=!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,n)=>{e.close(e=>{e?n(e):t()})})}})};var m=e=>{let t=c.NOT_READY;return{set:function(n,o){return t=n,e.emit(n,o),this},get:()=>t,setReady:function(){this.set(c.READY)},isReady:()=>t===c.READY}};var O=e=>{const t=new f.EventEmitter,n=m(t),o=v(e,n);return{status:n,init:function(){return u(this)},shutdown:function(e,t,n){return l(o,this)(e,t,n)},on:(e,n)=>t.on(e,n)}};const E=Object.assign((e,t)=>{var n;n=t,r&&(Object.freeze(Object.assign(o,n)),r=!1);const s=O(e).init();return{isReady:()=>s.status.isReady(),setReady:()=>s.status.setReady(),on:s.on}},c);t.default=E}]).default; | ||
module.exports=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=require("events")},function(e,t,n){"use strict";n.r(t);const o={closePromises:[],timeout:1e3,healthCheck:!0,livenessEndpoint:"/live",readinessEndpoint:"/ready"};let r=!0;var s=o;var i=[{type:"SIGHUP",code:1},{type:"SIGBREAK",code:1},{type:"SIGINT",code:2},{type:"SIGTERM",code:15},{type:"uncaughtException",code:2}];var a,u=e=>{for(const t of i)process.on(t.type,async n=>{await e.shutdown(t.type,t.code,n)});return e};!function(e){e.STARTING="STARTING",e.READY="READY",e.SHUTTING_DOWN="SHUTTING_DOWN",e.SHUTDOWN="SHUTDOWN"}(a||(a={}));var c=a;var l=e=>new Promise(t=>setTimeout(t,e));var d=(e,t)=>async(n,o,r)=>{const{timeout:i,closePromises:a}=s,u=r&&r.message?r:new Error(n);t.status.set(c.SHUTTING_DOWN,u),await l(i),await Promise.all(a.map(e=>e())),await e.stop(),t.status.set(c.SHUTDOWN,u),process.exit(128+o)},p=n(0);var f=e=>(t,n)=>{const{livenessEndpoint:o,readinessEndpoint:r}=s;if(!n.headersSent)return t.url===o&&"GET"===t.method?(n.statusCode=200,n.setHeader("Content-Type","application/json"),n.end(JSON.stringify({uptime:0|process.uptime()}))):t.url===r&&"GET"===t.method?e.isReady()?(n.statusCode=200,n.setHeader("Content-Type","application/json"),n.end(JSON.stringify({status:"ready"}))):(n.statusCode=503,n.end()):void 0};var y=e=>{const t=e||new Set,n=e=>{e.destroy(),t.delete(e)};return{onConnection:e=>{t.add(e),e.once("close",()=>t.delete(e))},closeAll:async()=>t.forEach(n)}};var m=(e,t)=>{const{healthCheck:n}=s,o=y(),r=y();let i=!1;e.on("connection",o.onConnection),e.on("secureConnection",r.onConnection);const a=e.listeners("request");e.removeAllListeners("request"),n&&e.on("request",f(t)),a.forEach(n=>e.on("request",(e,o)=>{t.isReady()?n(e,o):e.socket.destroy()}));return 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(),r.closeAll()]),new Promise((t,n)=>{e.close(e=>{e?n(e):t()})})}})};var v=e=>{let t=c.STARTING;return{set:function(n,o){return t=n,e.emit(n,o),this},get:()=>t,setReady:function(){this.set(c.READY)},isReady:()=>t===c.READY}};var T=e=>{const t=new p.EventEmitter,n=v(t),o=m(e,n);return{status:n,init:function(){return u(this)},shutdown:function(e,t,n){return d(o,this)(e,t,n)},on:(e,n)=>t.on(e,n)}};const S=Object.assign((e,t)=>{var n;n=t,r&&(Object.freeze(Object.assign(o,n)),r=!1);const s=T(e).init();return{isReady:()=>s.status.isReady(),setReady:()=>s.status.setReady(),on:s.on}},c);t.default=S}]);const __export__=module.exports;module.exports=__export__.default,Object.assign(module.exports,__export__); |
/// <reference types="node" /> | ||
import ImprovedServer from "../interface/improvedServer"; | ||
import IStatus from "../interface/status"; | ||
import http from 'http'; | ||
import * as http from 'http'; | ||
declare const improvedServer: (server: http.Server, serverStatus: IStatus) => ImprovedServer; | ||
export default improvedServer; |
/// <reference types="node" /> | ||
import ICore from "../interface/core"; | ||
import http from 'http'; | ||
import * as http from 'http'; | ||
declare const core: (server: http.Server) => ICore; | ||
export default core; |
/// <reference types="node" /> | ||
import net from 'net'; | ||
import * as net from 'net'; | ||
declare const SocketsPool: (sockets?: Set<net.Socket> | undefined) => { | ||
@@ -4,0 +4,0 @@ onConnection: (socket: net.Socket) => void; |
declare enum State { | ||
'NOT_READY' = "NOT_READY", | ||
'STARTING' = "STARTING", | ||
'READY' = "READY", | ||
'SHUTDOWN' = "SHUTDOWN", | ||
'SHUTTING_DOWN' = "SHUTTING_DOWN" | ||
'SHUTTING_DOWN' = "SHUTTING_DOWN", | ||
'SHUTDOWN' = "SHUTDOWN" | ||
} | ||
export default State; |
@@ -5,4 +5,4 @@ /// <reference types="node" /> | ||
import IGracefulServerOptions from "./interface/gracefulServerOptions"; | ||
import http from 'http'; | ||
import * as http from 'http'; | ||
declare const GracefulServer: ((server: http.Server, options?: IGracefulServerOptions | undefined) => IGracefulServer) & typeof State; | ||
export default GracefulServer; |
export default interface IGracefulServerOptions { | ||
closePromises?: (() => Promise<unknown>)[]; | ||
timeout?: number; | ||
healthCheck?: boolean; | ||
livenessEndpoint?: string; | ||
readinessEndpoint?: string; | ||
} |
/// <reference types="node" /> | ||
import http from 'http'; | ||
import * as http from 'http'; | ||
export default interface ImprovedServer extends http.Server { | ||
stop: () => Promise<void>; | ||
} |
export default interface IOptions { | ||
closePromises: (() => Promise<unknown>)[]; | ||
timeout: number; | ||
healthCheck: boolean; | ||
livenessEndpoint: string; | ||
readinessEndpoint: string; | ||
} |
/// <reference types="node" /> | ||
import IStatus from "../interface/status"; | ||
import http from 'http'; | ||
import * as http from 'http'; | ||
declare const onRequest: (serverStatus: IStatus) => (req: http.IncomingMessage, res: http.ServerResponse) => void; | ||
export default onRequest; |
@@ -30,3 +30,3 @@ { | ||
"license": "MIT", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "./lib/index.js", | ||
@@ -60,2 +60,3 @@ "types": "./lib/types/index.d.ts", | ||
"@typescript-eslint/parser": "^2.19.0", | ||
"add-module-exports-webpack-plugin": "^1.0.0", | ||
"babel-loader": "^8.0.6", | ||
@@ -62,0 +63,0 @@ "babel-plugin-module-resolver": "^4.0.0", |
@@ -27,3 +27,3 @@ <h1 align="center"> | ||
<p align="center"> | ||
Tiny (~5k), dependency-free Node.JS library to make your API more graceful | ||
Tiny (~5k), KISS, dependency-free Node.JS library to make your API more graceful | ||
</p> | ||
@@ -68,2 +68,6 @@ | ||
✔ Dependency-free. | ||
✔ KISS code base. | ||
## Requirements | ||
@@ -89,3 +93,3 @@ | ||
Below you can find the default endpoint but you can setup them. To do that, check out the [Options](#options) part. | ||
Below you can find the default endpoint but you can setup or disable them. To do that, check out the [Options](#options) part. | ||
@@ -210,3 +214,3 @@ <a name="lightship-behaviour-live"></a> | ||
where `State` is an enum that contains `READY`, `SHUTTING_DOWN` and `SHUTDOWN`. | ||
where `State` is an enum that contains, `STARTING`, `READY`, `SHUTTING_DOWN` and `SHUTDOWN`. | ||
@@ -221,2 +225,3 @@ ### IGracefulServerOptions | ||
| 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 | | ||
@@ -223,0 +228,0 @@ | readinessEndpoint | string | /ready | The readiness endpoint | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22355
108
391
38