♻️ Still don't know what I am doing. But basically the microservices are done.

This commit is contained in:
2025-07-14 00:09:32 +08:00
parent cde55eb237
commit 007da589bf
11 changed files with 37 additions and 38 deletions

View File

@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Hosting;
namespace DysonNetwork.Shared.Http;
public static class KestrelConfiguration
{
public static WebApplicationBuilder ConfigureAppKestrel(this WebApplicationBuilder builder)
{
builder.Host.UseContentRoot(Directory.GetCurrentDirectory());
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = 50 * 1024 * 1024;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30);
options.ConfigureEndpointDefaults(endpoints =>
{
endpoints.Protocols = HttpProtocols.Http1AndHttp2;
});
});
return builder;
}
}

View File

@@ -1,3 +1,4 @@
using System.Net;
using Grpc.Net.Client;
using System.Security.Cryptography.X509Certificates;
using Grpc.Core;
@@ -16,11 +17,14 @@ public static class GrpcClientHelper
{
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(
clientCertPassword is null ?
X509Certificate2.CreateFromPemFile(clientCertPath, clientKeyPath) :
X509Certificate2.CreateFromEncryptedPemFile(clientCertPath, clientCertPassword, clientKeyPath)
clientCertPassword is null
? X509Certificate2.CreateFromPemFile(clientCertPath, clientKeyPath)
: X509Certificate2.CreateFromEncryptedPemFile(clientCertPath, clientCertPassword, clientKeyPath)
);
return GrpcChannel.ForAddress(url, new GrpcChannelOptions { HttpHandler = handler }).CreateCallInvoker();
var httpClient = new HttpClient(handler);
httpClient.DefaultRequestVersion = HttpVersion.Version20;
httpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
return GrpcChannel.ForAddress(url, new GrpcChannelOptions { HttpClient = httpClient }).CreateCallInvoker();
}
private static async Task<string> GetServiceUrlFromEtcd(IEtcdClient etcdClient, string serviceName)
@@ -30,6 +34,7 @@ public static class GrpcClientHelper
{
throw new InvalidOperationException($"Service '{serviceName}' not found in Etcd.");
}
return response.Kvs[0].Value.ToStringUtf8();
}