Files
Hua.Todo/src/Hua.Todo.Host/Program.cs
T
ShaoHua 4fe0b5a963 feat: 完成云同步、语音控制与多平台扩展基础架构搭建
本次提交完成了项目核心基础架构升级:
1. 新增动态API中间件与权限控制系统,支持匿名/鉴权接口分离
2. 搭建云同步服务体系,包含认证、任务同步、安全策略等核心模块
3. 实现语音控制全链路,从STT/意图解析到命令执行
4. 新增任务类型、附件实体与相关仓储接口
5. 重构前端配置与代理规则,统一后端端口为5057
6. 新增多平台测试项目与CI脚本优化
7. 完善项目文档与代码注释规范

移除了旧版迁移文件与冗余代理配置,调整项目结构适配跨平台部署需求。
2026-06-21 03:26:04 +08:00

79 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Serilog;
using Hua.Todo.Application.Common;
using Hua.Todo.Application.Models;
using Hua.Todo.Application.Repositories;
using Hua.Todo.HttpApi;
using Hua.Todo.HttpApi.AspNetCore.CloudSync.Services;
using Hua.Todo.HttpApi.AspNetCore.DynamicApi;
using Hua.Todo.HttpApi.AspNetCore.DynamicApi.Swagger;
using Hua.Todo.HttpApi.AspNetCore.Mcp;
// 配置 Serilog 文件日志(开发环境统一到项目根目录 logs/)
Log.Logger = LoggingConfiguration.Create(
Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "logs"))).CreateLogger();
Log.Information("[Startup] Serilog 初始化完成");
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
Log.Information("[Startup] WebApplication.CreateBuilder 完成");
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.DocumentFilter<DynamicApiSwaggerDocumentFilter>();
});
Log.Information("[Startup] Swagger 注册完成");
builder.Services.AddApplicationServices("Data Source=Hua.Todo.db");
Log.Information("[Startup] AddApplicationServices 完成");
// 注册云同步服务端能力(认证 / RBAC / 二次认证 / 任务同步 / 安全策略)
builder.Services.AddCloudSyncServer();
Log.Information("[Startup] AddCloudSyncServer 完成");
// 注册 MCP Server(依赖 ITaskService,须在 AddApplicationServices 之后调用)
builder.Services.AddMcpServerServices();
Log.Information("[Startup] AddMcpServerServices 完成");
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
Log.Information("[Startup] DI 注册全部完成");
var app = builder.Build();
Log.Information("[Startup] builder.Build() 完成");
// Apply database migrations
using (var scope = app.Services.CreateScope())
{
Log.Information("[Startup] 开始 EF Core Migrate...");
var dbContext = scope.ServiceProvider.GetRequiredService<TodoDbContext>();
dbContext.Database.Migrate();
Log.Information("[Startup] EF Core Migrate 完成");
}
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.UseDynamicApi();
// 映射 MCP Server 端点(Streamable HTTP,路径 /mcp)
app.MapMcpServer();
app.Run();