chore: initial project import
This commit is contained in:
commit
3fc4e5ca53
347 files changed
+56172
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using Fleet.Server;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Monitor.Backend.Api;
|
||||
using Monitor.Backend.Application;
|
||||
using Monitor.Backend.Gateway;
|
||||
using Monitor.Backend.Storage.Sqlite;
|
||||
|
||||
namespace Monitor.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// 组合根:在这里显式注册所有层。配置来自 <c>appsettings.json</c>、环境变量(<c>Monitor__DataDirectory</c> 等)和命令行。
|
||||
/// 测试用 <see cref="Build"/> 在真实端口上启动整个后端。
|
||||
/// </summary>
|
||||
public static class BackendHost
|
||||
{
|
||||
public const string ConfigurationSection = "Monitor";
|
||||
public const int MaxRequestBodyBytes = 64 * 1024;
|
||||
|
||||
public static WebApplication Build(string[] args, Action<BackendOptions>? configureOptions = null, TimeProvider? time = null)
|
||||
{
|
||||
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
var options = new BackendOptions();
|
||||
builder.Configuration.GetSection(ConfigurationSection).Bind(options);
|
||||
configureOptions?.Invoke(options);
|
||||
|
||||
builder.WebHost.ConfigureKestrel(kestrel => kestrel.Limits.MaxRequestBodySize = MaxRequestBodyBytes);
|
||||
builder.Logging.AddSimpleConsole(console =>
|
||||
{
|
||||
console.SingleLine = true;
|
||||
console.UseUtcTimestamp = true;
|
||||
console.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
|
||||
});
|
||||
|
||||
IServiceCollection services = builder.Services;
|
||||
services.AddSingleton(time ?? TimeProvider.System);
|
||||
services.AddMonitorSqlite(options.DataDirectory);
|
||||
services.AddMonitorApplication(options);
|
||||
services.AddMonitorGateway();
|
||||
services.AddMonitorApi();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
// 静默死亡的 Agent(断电、断网)不会关闭连接:15 秒一个 Ping,20 秒没有 Pong 就关闭,这样面板上的在线状态才可信
|
||||
app.UseWebSockets(new WebSocketOptions { KeepAliveInterval = TimeSpan.FromSeconds(15), KeepAliveTimeout = TimeSpan.FromSeconds(20) });
|
||||
app.UseMonitorCors(options.CorsOrigins);
|
||||
app.UseMonitorApi();
|
||||
app.MapMonitorApi();
|
||||
app.MapFleetEnrollment("/api/agent/v1/enroll");
|
||||
app.MapFleetLink("/api/agent/v1/rpc");
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AssemblyName>monitor-backend</AssemblyName>
|
||||
<RootNamespace>Monitor.Backend</RootNamespace>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
|
||||
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
|
||||
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
|
||||
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)/../../openapi</OpenApiDocumentsDirectory>
|
||||
<OpenApiGenerateDocumentsOptions>--document-name v1 --file-name v1</OpenApiGenerateDocumentsOptions>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" PrivateAssets="all" />
|
||||
<ProjectReference Include="..\Monitor.Backend.Api\Monitor.Backend.Api.csproj" />
|
||||
<ProjectReference Include="..\Monitor.Backend.Gateway\Monitor.Backend.Gateway.csproj" />
|
||||
<ProjectReference Include="..\Monitor.Backend.Storage.Sqlite\Monitor.Backend.Storage.Sqlite.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,3 @@
|
||||
using Monitor.Backend;
|
||||
|
||||
await BackendHost.Build(args).RunAsync();
|
||||
Reference in new issue
Block a user