Rename projects to FileShare
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using FileShare_API.Configuration;
|
||||
using FileShare_API.Extensions;
|
||||
using FileShare_Common.Infrastructure;
|
||||
using FileShare_EFCore.Database;
|
||||
using FileShare_Services.Core;
|
||||
using Serilog;
|
||||
|
||||
// 初始化日志系统
|
||||
Log.Logger = LoggingConfiguration.CreateDefaultLogger(logDir: "logs");
|
||||
Log.Information("FileShare-API 正在启动...");
|
||||
|
||||
try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// 配置 Kestrel 监听所有本机 IP
|
||||
builder.WebHost.UseUrls("http://0.0.0.0:5206", "https://0.0.0.0:7165");
|
||||
|
||||
// 使用 Serilog 作为日志提供程序
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("LanFileViewer", policy =>
|
||||
policy.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod());
|
||||
});
|
||||
|
||||
// 注册统一端点及业务服务(入口在 FileShare-Services/Endpoints/AppEndpoints.cs)
|
||||
builder.Services.AddUnifiedApiServices(builder.Configuration);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// 初始化数据库(自动迁移 + 种子数据)
|
||||
app.Services.InitializeDatabase<AppDataContext>();
|
||||
|
||||
var endpoints = app.Services.GetRequiredService<ServiceEndpointCollection>();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/openapi/v1.json", "FileShare API v1");
|
||||
options.RoutePrefix = "swagger";
|
||||
});
|
||||
}
|
||||
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
// 局域网文件播放优先使用 HTTP,避免手机浏览器对自签 HTTPS/HTTP2 视频流的兼容问题。
|
||||
app.UseCors("LanFileViewer");
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// 将统一端点映射到 ASP.NET Core 路由
|
||||
app.MapUnifiedEndpoints(endpoints, app.Services);
|
||||
app.MapFileStreamEndpoints();
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "FileShare-API 启动失败");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
Reference in New Issue
Block a user