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';
3333
3434import CommunicationProtocolEnum from '../../enum/CommunicationProtocol.enum' ;
3535import { DaprClientOptions } from '../../types/DaprClientOptions' ;
36+ import { Settings } from '../../utils/Settings.util' ;
3637
3738export default class DaprClient {
3839 readonly daprHost : string ;
@@ -52,15 +53,15 @@ export default class DaprClient {
5253 readonly actor : IClientActorBuilder ;
5354
5455 constructor (
55- daprHost : string
56- , daprPort : string
56+ daprHost ? : string
57+ , daprPort ? : string
5758 , communicationProtocol : CommunicationProtocolEnum = CommunicationProtocolEnum . HTTP
5859 , options : DaprClientOptions = {
5960 isKeepAlive : true
6061 }
6162 ) {
62- this . daprHost = daprHost ;
63- this . daprPort = daprPort ;
63+ this . daprHost = daprHost ?? Settings . getDefaultHost ( ) ;
64+ this . daprPort = daprPort ?? Settings . getDefaultPort ( communicationProtocol ) ;
6465 this . communicationProtocol = communicationProtocol ;
6566 this . options = options ;
6667
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