diff --git a/DysonNetwork.Gateway/RegistryProxyConfigProvider.cs b/DysonNetwork.Gateway/RegistryProxyConfigProvider.cs index d497c9d..ef64b04 100644 --- a/DysonNetwork.Gateway/RegistryProxyConfigProvider.cs +++ b/DysonNetwork.Gateway/RegistryProxyConfigProvider.cs @@ -1,6 +1,7 @@ using System.Text; using dotnet_etcd.interfaces; using Yarp.ReverseProxy.Configuration; +using Yarp.ReverseProxy.Forwarder; namespace DysonNetwork.Gateway; @@ -14,8 +15,11 @@ public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable private CancellationTokenSource _cts; private IProxyConfig _config; - public RegistryProxyConfigProvider(IEtcdClient etcdClient, IConfiguration configuration, - ILogger logger) + public RegistryProxyConfigProvider( + IEtcdClient etcdClient, + IConfiguration configuration, + ILogger logger + ) { _etcdClient = etcdClient; _configuration = configuration; @@ -86,6 +90,10 @@ public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable Destinations = new Dictionary { { "destination1", new DestinationConfig { Address = serviceUrl } } + }, + HttpRequest = new ForwarderRequestConfig() + { + ActivityTimeout = directRoute.IsWebsocket ? TimeSpan.FromHours(24) : TimeSpan.FromMinutes(2) } }; clusters.Add(cluster); @@ -96,7 +104,7 @@ public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable RouteId = $"direct-{directRoute.Service}-{directRoute.Path.Replace("/", "-")}", ClusterId = directRoute.Service, Match = new RouteMatch { Path = directRoute.Path }, - TimeoutPolicy = directRoute.IsWebsocket ? "Disable" : null + Timeout = directRoute.IsWebsocket ? null : TimeSpan.FromSeconds(5), }; routes.Add(route); _logger.LogInformation(" Added Direct Route: {Path} -> {Service}", directRoute.Path, @@ -194,16 +202,25 @@ public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable { new() { { "PathRemovePrefix", $"/{pathAlias}" } }, new() { { "PathPrefix", "/api" } } - } + }, + Timeout = TimeSpan.FromSeconds(5) }; routes.Add(pathRoute); _logger.LogInformation(" Added Path-based Route: {Path}", pathRoute.Match.Path); } - return new CustomProxyConfig(routes, clusters, new Microsoft.Extensions.Primitives.CancellationChangeToken(_cts.Token)); + return new CustomProxyConfig( + routes, + clusters, + new Microsoft.Extensions.Primitives.CancellationChangeToken(_cts.Token) + ); } - private class CustomProxyConfig(IReadOnlyList routes, IReadOnlyList clusters, Microsoft.Extensions.Primitives.IChangeToken changeToken) + private class CustomProxyConfig( + IReadOnlyList routes, + IReadOnlyList clusters, + Microsoft.Extensions.Primitives.IChangeToken changeToken + ) : IProxyConfig { public IReadOnlyList Routes { get; } = routes; @@ -225,4 +242,4 @@ public class RegistryProxyConfigProvider : IProxyConfigProvider, IDisposable _watchCts.Cancel(); _watchCts.Dispose(); } -} +} \ No newline at end of file diff --git a/DysonNetwork.Gateway/Startup/ServiceCollectionExtensions.cs b/DysonNetwork.Gateway/Startup/ServiceCollectionExtensions.cs index 28a2153..08cbeaa 100644 --- a/DysonNetwork.Gateway/Startup/ServiceCollectionExtensions.cs +++ b/DysonNetwork.Gateway/Startup/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using DysonNetwork.Shared.Registry; +using Microsoft.AspNetCore.Http.Timeouts; using Yarp.ReverseProxy.Configuration; namespace DysonNetwork.Gateway.Startup; @@ -7,10 +8,15 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddGateway(this IServiceCollection services, IConfiguration configuration) { - services.AddReverseProxy(); + services + .AddReverseProxy() + .ConfigureHttpClient((context, handler) => + { + }); + services.AddRegistryService(configuration); services.AddSingleton(); return services; } -} +} \ No newline at end of file diff --git a/DysonNetwork.Gateway/appsettings.json b/DysonNetwork.Gateway/appsettings.json index 683c3ab..b8a754c 100644 --- a/DysonNetwork.Gateway/appsettings.json +++ b/DysonNetwork.Gateway/appsettings.json @@ -31,7 +31,7 @@ { "Path": "/ws", "Service": "DysonNetwork.Pusher", - "IsWebSocket": true + "IsWebsocket": true }, { "Path": "/.well-known/openid-configuration", diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index 56e9a8c..94af7c4 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -17,6 +17,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -59,6 +60,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -89,8 +91,10 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded