File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import HTTPClient from './HTTPClient/HTTPClient';
33
33
34
34
import CommunicationProtocolEnum from '../../enum/CommunicationProtocol.enum' ;
35
35
import { DaprClientOptions } from '../../types/DaprClientOptions' ;
36
+ import { Settings } from '../../utils/Settings.util' ;
36
37
37
38
export default class DaprClient {
38
39
readonly daprHost : string ;
@@ -52,15 +53,15 @@ export default class DaprClient {
52
53
readonly actor : IClientActorBuilder ;
53
54
54
55
constructor (
55
- daprHost : string
56
- , daprPort : string
56
+ daprHost ? : string
57
+ , daprPort ? : string
57
58
, communicationProtocol : CommunicationProtocolEnum = CommunicationProtocolEnum . HTTP
58
59
, options : DaprClientOptions = {
59
60
isKeepAlive : true
60
61
}
61
62
) {
62
- this . daprHost = daprHost ;
63
- this . daprPort = daprPort ;
63
+ this . daprHost = daprHost ?? Settings . getDefaultHost ( ) ;
64
+ this . daprPort = daprPort ?? Settings . getDefaultPort ( communicationProtocol ) ;
64
65
this . communicationProtocol = communicationProtocol ;
65
66
this . options = options ;
66
67
Original file line number Diff line number Diff line change
1
+ import CommunicationProtocolEnum from "../enum/CommunicationProtocol.enum" ;
2
+
3
+ export class Settings {
4
+ private static readonly defaultHost : string = "127.0.0.1" ;
5
+ private static readonly defaultHttpPort : string = "3500" ;
6
+ private static readonly defaultGrpcPort : string = "50001" ;
7
+
8
+ static getDefaultHost ( ) : string {
9
+ return Settings . defaultHost ;
10
+ }
11
+
12
+ static getDefaultHttpPort ( ) : string {
13
+ return process . env . DAPR_HTTP_PORT ?? Settings . defaultHttpPort ;
14
+ }
15
+
16
+ static getDefaultGrpcPort ( ) : string {
17
+ return process . env . DAPR_GRPC_PORT ?? Settings . defaultGrpcPort ;
18
+ }
19
+
20
+ static getDefaultPort ( communicationProtocolEnum : CommunicationProtocolEnum ) : string {
21
+ switch ( communicationProtocolEnum ) {
22
+ case CommunicationProtocolEnum . GRPC :
23
+ return this . getDefaultGrpcPort ( ) ;
24
+ default :
25
+ return this . getDefaultHttpPort ( ) ;
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments