@gquittet/graceful-server
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -1,1 +0,1 @@ | ||
const e={closePromises:[],timeout:1e3,healthCheck:!0,kubernetes:!1,livenessEndpoint:"/live",readinessEndpoint:"/ready"};let t=!0;const o=r=>(t&&(Object.freeze(Object.assign(e,r)),t=!1),e);var i=e;export{i as default,o as makeOptions}; | ||
const e={syncClose:!1,closePromises:[],timeout:1e3,healthCheck:!0,kubernetes:!1,livenessEndpoint:"/live",readinessEndpoint:"/ready"};let t=!0;const s=r=>(t&&(Object.freeze(Object.assign(e,r)),t=!1),e);var o=e;export{o as default,s as makeOptions}; |
@@ -1,1 +0,1 @@ | ||
import{exit as k}from"node:process";import l from"#config/index";import d from"#core/socketsPool";import h from"#core/state";import g from"#util/onRequest";import E from"#util/sleep";const{livenessEndpoint:P,readinessEndpoint:T}=l,b=(e,n)=>{const{healthCheck:y,kubernetes:S}=l,p=d(),m=d();let a=!1;e.on("connection",p.onConnection),e.on("secureConnection",m.onConnection);const f=e.listeners("request");return e.removeAllListeners("request"),y?(e.on("request",g(n)),f.forEach(o=>e.on("request",(t,i)=>{if(S?!n.isReady()&&!n.isShuttingDown():!n.isReady())return t.socket.destroy();if(t.url!==P&&t.url!==T||t.method!=="GET")return o(t,i)}))):f.forEach(o=>e.on("request",(t,i)=>{if(n.isReady())return o(t,i);t.socket.destroy()})),Object.assign(e,{stop:async(o={value:0})=>{if(!e.listening||a)return;a=!0;const{timeout:t,closePromises:i}=l;let s;o.body&&o.body.message?s=o.body:o.type&&(s=new Error(o.type)),n.set(h.SHUTTING_DOWN,s),await E(t),await Promise.all(i.map(r=>r())),e.removeAllListeners("request"),e.on("request",(r,c)=>{c.headersSent||c.setHeader("connection","close")}),await Promise.all([p.closeAll(),m.closeAll()]),await new Promise((r,c)=>{e.close(u=>u?c(u):r(s)),n.set(h.SHUTDOWN,s),k(o.value)})}})};var x=b;export{x as default}; | ||
import{exit as P}from"node:process";import l from"#config/index";import y from"#core/socketsPool";import h from"#core/state";import g from"#util/onRequest";import w from"#util/sleep";const{livenessEndpoint:E,readinessEndpoint:T}=l,b=(e,n)=>{const{healthCheck:S,kubernetes:k}=l,p=y(),m=y();let a=!1;e.on("connection",p.onConnection),e.on("secureConnection",m.onConnection);const f=e.listeners("request");return e.removeAllListeners("request"),S?(e.on("request",g(n)),f.forEach(o=>e.on("request",(t,s)=>{if(k?!n.isReady()&&!n.isShuttingDown():!n.isReady())return t.socket.destroy();if(t.url!==E&&t.url!==T||t.method!=="GET")return o(t,s)}))):f.forEach(o=>e.on("request",(t,s)=>{if(n.isReady())return o(t,s);t.socket.destroy()})),Object.assign(e,{stop:async(o={value:0})=>{if(!e.listening||a)return;a=!0;const{timeout:t,closePromises:s,syncClose:u}=l;let r;if(o.body&&o.body.message?r=o.body:o.type&&(r=new Error(o.type)),n.set(h.SHUTTING_DOWN,r),await w(t),u)for(const i of s)await i();else await Promise.allSettled(s.map(i=>i()));e.removeAllListeners("request"),e.on("request",(i,c)=>{c.headersSent||c.setHeader("connection","close")}),await Promise.allSettled([p.closeAll(),m.closeAll()]),await new Promise((i,c)=>{e.close(d=>d?c(d):i(r)),n.set(h.SHUTDOWN,r),P(o.value)})}})};var H=b;export{H as default}; |
export type IGracefulServerOptions = { | ||
syncClose?: boolean; | ||
closePromises?: (() => Promise<unknown>)[]; | ||
@@ -3,0 +4,0 @@ timeout?: number; |
export type IOptions = { | ||
syncClose: boolean; | ||
closePromises: (() => Promise<unknown>)[]; | ||
@@ -3,0 +4,0 @@ timeout: number; |
{ | ||
"name": "@gquittet/graceful-server", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Tiny (~5k), dependency-free Node.JS library to make your API more graceful", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -322,3 +322,4 @@ <h1 align="center"> | ||
| Name | Type | Default | Description | | ||
| ----------------- | :------------------------: | :-----: | ---------------------------------------------------------------: | | ||
|-------------------|:--------------------------:|:-------:|-----------------------------------------------------------------:| | ||
| syncClose | boolean | false | Run the closePromises in a series. | | ||
| closePromises | (() => Promise<unknown>)[] | [] | The functions to run when the API is stopping | | ||
@@ -325,0 +326,0 @@ | timeout | number | 1000 | The time in milliseconds to wait before shutting down the server | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
4
528
34047
62
201