File tree Expand file tree Collapse file tree 5 files changed +100
-2
lines changed
Expand file tree Collapse file tree 5 files changed +100
-2
lines changed Original file line number Diff line number Diff line change 33 "version" : " 1.0.0" ,
44 "description" : " " ,
55 "main" : " index.js" ,
6+ "types" : " ./typings/index.d.ts" ,
67 "scripts" : {
7- "test" : " mocha lib/**/*.spec.js" ,
8+ "test-typings" : " tsc --lib ES2015 --noEmit typings/*.ts" ,
9+ "test" : " mocha lib/**/*.spec.js && npm run test-typings" ,
810 "eslint" : " eslint-godaddy -c .eslintrc lib example index.js" ,
911 "coverage" : " nyc mocha lib/**/*.spec.js" ,
1012 "publish" : " npm run eslint && npm test" ,
2224 "stoppable" : " ^1.0.5"
2325 },
2426 "devDependencies" : {
27+ "@types/express" : " ^4.0.39" ,
28+ "@types/koa" : " ^2.0.42" ,
29+ "@types/node" : " ^8.0.58" ,
2530 "chai" : " ^4.1.2" ,
2631 "eslint" : " ^4.4.1" ,
2732 "eslint-config-godaddy" : " ^2.0.0" ,
3136 "mocha" : " ^4.0.1" ,
3237 "node-fetch" : " ^1.7.3" ,
3338 "nyc" : " ^11.3.0" ,
39+ "semantic-release" : " ^8.2.0" ,
3440 "supertest" : " ^3.0.0" ,
35- "semantic-release " : " ^8.2.0 "
41+ "typescript " : " ^2.6.2 "
3642 }
3743}
Original file line number Diff line number Diff line change 1+ import * as http from "http" ;
2+ import * as terminus from "@godaddy/terminus" ;
3+ import * as express from "express" ;
4+
5+ const app = express ( ) ;
6+
7+ app . get ( "/" , ( req , res ) => res . send ( "ok" ) ) ;
8+
9+ const server = http . createServer ( app ) ;
10+
11+ function onHealthCheck ( ) {
12+ return Promise . resolve ( ) ;
13+ }
14+
15+ terminus ( http . createServer ( app ) , {
16+ logger : console . log ,
17+ healthChecks : {
18+ "/healthcheck" : ( ) => Promise . resolve ( )
19+ }
20+ } ) . listen ( 3000 ) ;
Original file line number Diff line number Diff line change 1+ declare module "@godaddy/terminus" {
2+
3+ type HealthCheck = ( ) => Promise < any > ;
4+
5+ interface HealthCheckMap {
6+ [ key : string ] : HealthCheck ;
7+ }
8+
9+ interface TerminusOptions {
10+ healthChecks ?: HealthCheckMap ;
11+ timeout ?: number ;
12+ onSigterm ?: ( ) => Promise < any > ;
13+ onShutdown ?: ( ) => Promise < any > ;
14+ logger ?: ( msg : string , err : Error ) => void ;
15+ }
16+
17+ type Terminus = < T > ( server : T , options ?: TerminusOptions ) => T ;
18+
19+ const terminus : Terminus ;
20+
21+ export = terminus ;
22+ }
Original file line number Diff line number Diff line change 1+ import * as http from "http" ;
2+ import * as terminus from "@godaddy/terminus" ;
3+
4+ async function onSigterm ( ) {
5+ console . log ( 'server is starting cleanup' ) ;
6+ return Promise . all ( [
7+ // your clean logic, like closing database connections
8+ ] ) ;
9+ }
10+
11+ async function onShutdown ( ) {
12+ console . log ( 'cleanup finished, server is shutting down' ) ;
13+ return Promise . resolve ( ) ;
14+ }
15+
16+ const server = http . createServer ( ( request , response ) => {
17+ response . end ( '<html><body><h1>Hello, World!</h1></body></html>' ) ;
18+ } )
19+
20+ terminus ( server , {
21+ healthChecks : {
22+ "/healthcheck" : ( ) => Promise . resolve ( )
23+ } ,
24+ timeout : 1000 ,
25+ onSigterm,
26+ onShutdown,
27+ logger : console . log
28+ } ) ;
29+
30+ server . listen ( 3000 ) ;
Original file line number Diff line number Diff line change 1+ import * as http from "http" ;
2+ import * as terminus from "@godaddy/terminus" ;
3+ import * as Koa from "koa" ;
4+
5+ const app = new Koa ( ) ;
6+
7+ const server = http . createServer ( app . callback ( ) ) ;
8+
9+ function onHealthCheck ( ) {
10+ return Promise . resolve ( ) ;
11+ }
12+
13+ terminus ( server , {
14+ logger : console . log ,
15+ healthChecks : {
16+ "/healthcheck" : ( ) => Promise . resolve ( )
17+ }
18+ } ) ;
19+
20+ server . listen ( 3000 ) ;
You can’t perform that action at this time.
0 commit comments