配置静态文件与首页路径

This commit is contained in:
lihanbo 2024-10-18 11:30:00 +08:00
parent f171251921
commit 4c6b9b567a
1 changed files with 10 additions and 1 deletions

View File

@ -81,7 +81,12 @@ public static class Program
options.GetLevel = (httpContext, elapsed, ex) => LogEventLevel.Information;
});
app.MapControllers();
// app.MapGet("/", () => "Hello World!");
// 添加根目录映射
app.MapGet("/", async context =>
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(Path.Combine(app.Environment.WebRootPath, "index.html"));
});
// if (app.Environment.IsDevelopment())
{
app.UseSwagger();
@ -97,6 +102,10 @@ public static class Program
Log.Logger.Information("ApplicationStarted");
CodeFirst.InitTable();
});
// 启用静态文件支持
app.UseStaticFiles();
app.UseCors("AllowAny");
app.Run();
}