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 defaultHttpAppPort : string = "3000" ;
6
+ private static readonly defaultHttpPort : string = "3500" ;
7
+ private static readonly defaultGrpcAppPort : string = "50000" ;
8
+ private static readonly defaultGrpcPort : string = "50001" ;
9
+
10
+ static getDefaultHost ( ) : string {
11
+ return Settings . defaultHost ;
12
+ }
13
+
14
+ static getDefaultHttpPort ( ) : string {
15
+ return process . env . DAPR_HTTP_PORT ?? Settings . defaultHttpPort ;
16
+ }
17
+
18
+ static getDefaultGrpcPort ( ) : string {
19
+ return process . env . DAPR_GRPC_PORT ?? Settings . defaultGrpcPort ;
20
+ }
21
+
22
+ /**
23
+ * Gets the default port that the Dapr sidecar is listening to.
24
+ * @param communicationProtocolEnum communication protocol
25
+ * @returns port number
26
+ */
27
+ static getDefaultPort ( communicationProtocolEnum : CommunicationProtocolEnum ) : string {
28
+ switch ( communicationProtocolEnum ) {
29
+ case CommunicationProtocolEnum . GRPC :
30
+ return this . getDefaultGrpcPort ( ) ;
31
+ default :
32
+ return this . getDefaultHttpPort ( ) ;
33
+ }
34
+ }
35
+
36
+ static getDefaultHttpAppPort ( ) : string {
37
+ return process . env . APP_PORT ?? Settings . defaultHttpAppPort ;
38
+ }
39
+
40
+ static getDefaultGrpcAppPort ( ) : string {
41
+ return process . env . APP_PORT ?? Settings . defaultGrpcAppPort ;
42
+ }
43
+
44
+ /**
45
+ * Gets the default port that the application is listening on.
46
+ * @param communicationProtocolEnum communication protocol
47
+ * @returns port number
48
+ */
49
+ static getDefaultAppPort ( communicationProtocolEnum : CommunicationProtocolEnum ) : string {
50
+ switch ( communicationProtocolEnum ) {
51
+ case CommunicationProtocolEnum . GRPC :
52
+ return this . getDefaultGrpcAppPort ( ) ;
53
+ default :
54
+ return this . getDefaultHttpAppPort ( ) ;
55
+ }
56
+ }
57
+ }
0 commit comments