This commit is contained in:
fuenmao
2026-10-09 16:46:30 +08:00
parent 4a634ef4c2
commit e6b90a06ab
63 changed files with 4170 additions and 1518 deletions
+21 -9
View File
@@ -9,6 +9,7 @@ using Admin.NET.Core.ElasticSearch;
using Admin.NET.Core.Service;
using AspNetCoreRateLimit;
using Evergreen.Health.Application.Health.Integrations.HomeAssistant;
using Evergreen.Health.Application.Health.Devices;
using Evergreen.Health.Application.Health.Integrations.MiAirX;
using Furion;
using Furion.Logging;
@@ -17,12 +18,14 @@ using Furion.VirtualFileServer;
using IPTools.Core;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OnceMi.AspNetCore.OSS;
using Scalar.AspNetCore;
@@ -78,10 +81,7 @@ public class Startup : AppStartup
services.AddHttpRemote();
services.AddHttpClient<HomeAssistantClient>();
services.AddHttpClient<MiAirXClient>();
services.AddSingleton<TcmMusicTransitionService>();
services.AddHostedService(provider => provider.GetRequiredService<TcmMusicTransitionService>());
services.AddSingleton<HomeAssistantLightTransitionService>();
services.AddHostedService(provider => provider.GetRequiredService<HomeAssistantLightTransitionService>());
services.AddHealthDevices();
// 任务队列
services.AddTaskQueue();
// 脱敏检测
@@ -104,7 +104,8 @@ public class Startup : AppStartup
}
;
services.AddControllersWithViews()
// 后端只提供 API;移动端页面位于独立的 Mobile 项目。
services.AddControllers()
.AddAppLocalization()
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
//.AddXmlSerializerFormatters()
@@ -287,7 +288,19 @@ public class Startup : AppStartup
}
else
{
app.UseExceptionHandler("/Home/Error");
// API 未处理异常保持 JSON 响应;原 /Home/Error 没有对应处理入口。
app.UseExceptionHandler(errorApp => errorApp.Run(async context =>
{
var exception = context.Features.Get<IExceptionHandlerFeature>()?.Error;
context.RequestServices.GetRequiredService<ILogger<Startup>>()
.LogError(exception, "请求发生未处理异常,TraceId={TraceId}", context.TraceIdentifier);
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
await context.Response.WriteAsJsonAsync(new
{
code = 500, type = "error", message = "服务暂时不可用,请稍后重试",
result = (object)null, extras = new { traceId = context.TraceIdentifier }
}, context.RequestAborted);
}));
app.UseHsts();
}
@@ -373,9 +386,8 @@ public class Startup : AppStartup
// 注册集线器
endpoints.MapHubs();
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
// 健康接口和后台接口均使用特性路由,不再保留默认欢迎页。
endpoints.MapControllers();
});
}
}