diff --git a/.aspire/settings.json b/.aspire/settings.json new file mode 100644 index 0000000..978c755 --- /dev/null +++ b/.aspire/settings.json @@ -0,0 +1,3 @@ +{ + "appHostPath": "../src/HelloShop.AppHost/HelloShop.AppHost.csproj" +} \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 1590369..15d0163 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,14 +4,14 @@ true - - - - - - - - + + + + + + + + diff --git a/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs b/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs index 8c7cb94..311d10b 100644 --- a/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs +++ b/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs @@ -20,9 +20,12 @@ public class OpenApiConfigureOptions(IConfiguredServiceEndPointResolver serviceR UriBuilder uriBuilder = new(endPoint) { Path = "/openapi/v1.json" }; try - { + { HttpRequestMessage request = new(HttpMethod.Get, uriBuilder.Uri) { Version = new Version(2, 0) }; - HttpResponseMessage response = httpClient.SendAsync(request).GetAwaiter().GetResult(); + + using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5)); + HttpResponseMessage response = httpClient.SendAsync(request, cts.Token).GetAwaiter().GetResult(); + if (response.IsSuccessStatusCode) { urlDescriptors.Add(new UrlDescriptor @@ -32,18 +35,35 @@ public class OpenApiConfigureOptions(IConfiguredServiceEndPointResolver serviceR }); break; } + else + { + if (logger.IsEnabled(LogLevel.Warning)) + { + logger.LogWarning("Failed to get swagger endpoint for {ServiceName} at {Endpoint}, Status: {StatusCode}", + serviceEndpoint.ServiceName, uriBuilder.Uri, response.StatusCode); + } + } + } + catch (OperationCanceledException) + { + if (logger.IsEnabled(LogLevel.Warning)) + { + logger.LogWarning("Timeout getting swagger endpoint for {ServiceName} at {Endpoint}", + serviceEndpoint.ServiceName, uriBuilder.Uri); + } } catch (Exception ex) { - if (logger.IsEnabled(LogLevel.Error)) + if (logger.IsEnabled(LogLevel.Warning)) { - logger.LogError(ex, "Failed to get swagger endpoint for {ServiceName}", serviceEndpoint.ServiceName); + logger.LogWarning(ex, "Failed to get swagger endpoint for {ServiceName} at {Endpoint}", + serviceEndpoint.ServiceName, uriBuilder.Uri); } } } } - options.ConfigObject.Urls = urlDescriptors; + options.ConfigObject.Urls = urlDescriptors; options.SwaggerEndpoint("/openapi/v1.json", "apiservice"); } } diff --git a/src/HelloShop.ApiService/Program.cs b/src/HelloShop.ApiService/Program.cs index bc0a262..794d905 100644 --- a/src/HelloShop.ApiService/Program.cs +++ b/src/HelloShop.ApiService/Program.cs @@ -25,6 +25,12 @@ builder.Services.AddReverseProxy() builder.Services.AddSingleton(); builder.Services.AddSingleton(); + +builder.Services.AddHttpClient(client => +{ + client.Timeout = TimeSpan.FromSeconds(30); +}); + builder.Services.AddTransient, OpenApiConfigureOptions>(); builder.Services.AddTransient(); diff --git a/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml b/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml index 9839bc6..2eada91 100644 --- a/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml +++ b/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml @@ -10,5 +10,7 @@ spec: value: "localhost:6379" - name: redisPassword value: "guest" + - name: enableTLS + value: "true" auth: secretStore: env-secretstore \ No newline at end of file diff --git a/src/HelloShop.AppHost/HelloShop.AppHost.csproj b/src/HelloShop.AppHost/HelloShop.AppHost.csproj index 5d122a8..cf1d02e 100644 --- a/src/HelloShop.AppHost/HelloShop.AppHost.csproj +++ b/src/HelloShop.AppHost/HelloShop.AppHost.csproj @@ -1,4 +1,4 @@ - + Exe net10.0 diff --git a/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj b/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj index a1120a4..39606aa 100644 --- a/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj +++ b/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj @@ -62,8 +62,8 @@ - - + +