@@ -4,6 +4,7 @@ import HTTPServerImpl from "./HTTPServerImpl";
44import IServer from "../../../interfaces/Server/IServer" ;
55import * as NodeJSUtils from "../../../utils/NodeJS.util" ;
66import { DaprClient } from "../../.." ;
7+ import { createHttpTerminator } from 'http-terminator' ;
78
89// eslint-disable-next-line
910export interface IServerImplType extends HTTPServerImpl { }
@@ -17,7 +18,7 @@ export default class HTTPServer implements IServer {
1718 server : IServerType ;
1819 serverAddress : string ;
1920 serverImpl : IServerImplType ;
20- serverStartupDelay = 1000 ; // @todo : use health api https://docs.dapr.io/reference/api/health_api/
21+ daprSidecarPollingDelayMs = 1000 ;
2122 client : DaprClient ;
2223
2324 constructor ( client : DaprClient ) {
@@ -109,7 +110,7 @@ export default class HTTPServer implements IServer {
109110 console . log ( `[Dapr-JS] Letting Dapr pick-up the server (Maximum 60s wait time)` ) ;
110111 while ( ! isHealthy ) {
111112 console . log ( `[Dapr-JS] - Waiting till Dapr Started (#${ isHealthyRetryCount } )` ) ;
112- await NodeJSUtils . sleep ( this . serverStartupDelay ) ;
113+ await NodeJSUtils . sleep ( this . daprSidecarPollingDelayMs ) ;
113114 isHealthy = await this . client . health . isHealthy ( ) ;
114115 isHealthyRetryCount ++ ;
115116
@@ -124,7 +125,9 @@ export default class HTTPServer implements IServer {
124125 }
125126
126127 async stop ( ) : Promise < void > {
127- await this . server . close ( ) ;
128+ const httpTerminator = createHttpTerminator ( { server : this . server . getServer ( ) } ) ;
129+ await httpTerminator . terminate ( ) ;
130+ // await this.server.close();
128131 this . isInitialized = false ;
129132 }
130133}
0 commit comments