@@ -4,6 +4,7 @@ import HTTPServerImpl from "./HTTPServerImpl";
4
4
import IServer from "../../../interfaces/Server/IServer" ;
5
5
import * as NodeJSUtils from "../../../utils/NodeJS.util" ;
6
6
import { DaprClient } from "../../.." ;
7
+ import { createHttpTerminator } from 'http-terminator' ;
7
8
8
9
// eslint-disable-next-line
9
10
export interface IServerImplType extends HTTPServerImpl { }
@@ -17,7 +18,7 @@ export default class HTTPServer implements IServer {
17
18
server : IServerType ;
18
19
serverAddress : string ;
19
20
serverImpl : IServerImplType ;
20
- serverStartupDelay = 1000 ; // @todo : use health api https://docs.dapr.io/reference/api/health_api/
21
+ daprSidecarPollingDelayMs = 1000 ;
21
22
client : DaprClient ;
22
23
23
24
constructor ( client : DaprClient ) {
@@ -109,7 +110,7 @@ export default class HTTPServer implements IServer {
109
110
console . log ( `[Dapr-JS] Letting Dapr pick-up the server (Maximum 60s wait time)` ) ;
110
111
while ( ! isHealthy ) {
111
112
console . log ( `[Dapr-JS] - Waiting till Dapr Started (#${ isHealthyRetryCount } )` ) ;
112
- await NodeJSUtils . sleep ( this . serverStartupDelay ) ;
113
+ await NodeJSUtils . sleep ( this . daprSidecarPollingDelayMs ) ;
113
114
isHealthy = await this . client . health . isHealthy ( ) ;
114
115
isHealthyRetryCount ++ ;
115
116
@@ -124,7 +125,9 @@ export default class HTTPServer implements IServer {
124
125
}
125
126
126
127
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();
128
131
this . isInitialized = false ;
129
132
}
130
133
}
0 commit comments