All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
91 lines
4.1 KiB
C#
91 lines
4.1 KiB
C#
using System.Security.Authentication;
|
||
using Fake.AspNetCore;
|
||
using Fake.EventBus.RabbitMQ;
|
||
using Fake.Modularity;
|
||
using Fake.ObjectMapping.AutoMapper;
|
||
using Fake.ObjectStorage;
|
||
using Fake.RabbitMQ;
|
||
using FreeRedis;
|
||
using InterfaceForward.Application.Contracts;
|
||
using InterfaceForward.Application.Contracts.ForwardCore;
|
||
using InterfaceForward.Application.ForwardCore;
|
||
using InterfaceForward.Application.Helpers;
|
||
using InterfaceForward.Application.HostServices;
|
||
using InterfaceForward.Domain.Shared;
|
||
using InterfaceForward.Repositories;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
namespace InterfaceForward.Application;
|
||
|
||
[DependsOn(typeof(FakeRabbitMqModule))]
|
||
[DependsOn(typeof(FakeAspNetCoreModule))]
|
||
[DependsOn(typeof(FakeObjectMappingAutoMapperModule))]
|
||
[DependsOn(typeof(FakeEventBusRabbitMqModule))]
|
||
[DependsOn(typeof(FakeObjectStorageTencentCosModule))]
|
||
[DependsOn(typeof(InterfaceForwardRepositoriesModule))]
|
||
[DependsOn(typeof(InterfaceForwardDomainSharedModule))]
|
||
public class InterfaceForwardApplicationModule:FakeModule
|
||
{
|
||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||
{
|
||
var configuration = context.Services.GetConfiguration();
|
||
|
||
context.Services.Configure<FakeAutoMapperOptions>(options =>
|
||
{
|
||
options.ScanProfiles<InterfaceForwardApplicationModule>();
|
||
});
|
||
|
||
context.Services.Configure<InterfaceRelayOptions>(configuration.GetSection("InterfaceRelay"));
|
||
|
||
context.Services.AddHostedService<AppSubscribeHostService>();
|
||
|
||
var options = configuration.GetSection("Redis").Get<ConnectionStringBuilder>();
|
||
if (options == null)
|
||
throw new FakeException("未找到Redis相关配置,请检查配置文件中是否包含名为Redis的节点");
|
||
RedisHelper.Init(options, showLogInfo: System.Diagnostics.Debugger.IsAttached);
|
||
|
||
// 预热并验证动态脚本编译环境。
|
||
PreheatNatasha();
|
||
|
||
context.Services.AddHttpClient("forward", client => { client.Timeout = TimeSpan.FromSeconds(20); })
|
||
.ConfigurePrimaryHttpMessageHandler(_ =>
|
||
{
|
||
var httpClientHandler = new HttpClientHandler();
|
||
// 确保支持较新的 SSL/TLS 版本
|
||
httpClientHandler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
|
||
// 忽略 SSL/TLS 证书错误
|
||
httpClientHandler.ServerCertificateCustomValidationCallback =
|
||
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
|
||
return httpClientHandler;
|
||
});
|
||
}
|
||
|
||
static void PreheatNatasha()
|
||
{
|
||
// aspnet 非 root 时 /app 不可写;k8s 已在 api.yaml 挂 emptyDir → /app/DynamicLibraryFolders
|
||
Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "DynamicLibraryFolders"));
|
||
|
||
NatashaManagement.Preheating<NatashaDomainCreator>(false, false);
|
||
|
||
var context = new ForwardCoreContext();
|
||
NatashaScriptCompiler.CompileAction("""
|
||
obj.FormFieldList.Add(new InterfaceForward.Domain.Shared.Dtos.InterfaceFormFieldDto
|
||
{
|
||
Name = "_natasha_health",
|
||
Value = "ok"
|
||
});
|
||
""")(context);
|
||
|
||
NatashaScriptCompiler.CompileAsyncFunc("""
|
||
//async
|
||
await System.Threading.Tasks.Task.CompletedTask;
|
||
obj.FormFieldList.Add(new InterfaceForward.Domain.Shared.Dtos.InterfaceFormFieldDto
|
||
{
|
||
Name = "_natasha_async_health",
|
||
Value = "ok"
|
||
});
|
||
""")(context).GetAwaiter().GetResult();
|
||
}
|
||
}
|