Skip to content

Commit

Permalink
Made some lines a little more concise, added hostname default to Dapr…
Browse files Browse the repository at this point in the history
…Defaults to use when building endpoints.

Signed-off-by: Whit Waldo <[email protected]>
  • Loading branch information
WhitWaldo committed Oct 15, 2024
1 parent ef25775 commit 616638f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ internal static string GetHttpEndpoint(IConfiguration? configuration)
//Prioritize pulling from IConfiguration with a fallback of pulling from the environment variable directly
var httpEndpoint = GetResourceValue(configuration, DaprDefaults.DaprHttpEndpointName);
var httpPort = GetResourceValue(configuration, DaprDefaults.DaprHttpPortName);
int? parsedHttpPort = string.IsNullOrWhiteSpace(httpPort) ? null : int.Parse(httpPort);
int? parsedHttpPort = int.TryParse(httpPort, out var port) ? port : null;

var endpoint = BuildEndpoint(httpEndpoint, parsedHttpPort);
return string.IsNullOrWhiteSpace(endpoint) ? $"http://localhost:{DaprDefaults.DefaultHttpPort}/" : endpoint;
return string.IsNullOrWhiteSpace(endpoint)
? $"http://{DaprDefaults.DaprHostName}:{DaprDefaults.DefaultHttpPort}/"
: endpoint;
}

/// <summary>
Expand All @@ -135,10 +137,12 @@ internal static string GetGrpcEndpoint(IConfiguration? configuration)
//Prioritize pulling from IConfiguration with a fallback from pulling from the environment variable directly
var grpcEndpoint = GetResourceValue(configuration, DaprDefaults.DaprGrpcEndpointName);
var grpcPort = GetResourceValue(configuration, DaprDefaults.DaprGrpcPortName);
int? parsedGrpcPort = string.IsNullOrWhiteSpace(grpcPort) ? null : int.Parse(grpcPort);
int? parsedGrpcPort = int.TryParse(grpcPort, out var port) ? port : null;

var endpoint = BuildEndpoint(grpcEndpoint, parsedGrpcPort);
return string.IsNullOrWhiteSpace(endpoint) ? $"http://localhost:{DaprDefaults.DefaultGrpcPort}/" : endpoint;
return string.IsNullOrWhiteSpace(endpoint)
? $"http://{DaprDefaults.DaprHostName}:{DaprDefaults.DefaultGrpcPort}/"
: endpoint;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Shared/DaprDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static class DaprDefaults
public const string DaprGrpcEndpointName = "DAPR_GRPC_ENDPOINT";
public const string DaprGrpcPortName = "DAPR_GRPC_PORT";

public const string DaprHostName = "localhost";
public const int DefaultHttpPort = 3500;
public const int DefaultGrpcPort = 50001;

Expand Down

0 comments on commit 616638f

Please sign in to comment.