Compare commits

..
3 Commits
Author SHA1 Message Date
xrain 3445531972 add cors 2021-06-05 14:33:59 +08:00
xrain 2268ad0c8c add cors 2021-06-05 14:30:52 +08:00
xrain 0b6c6af51d add httpcontextaccessor for simapistorage 2021-06-05 12:07:47 +08:00
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -4,6 +4,7 @@ namespace SimApi.Configs
{ {
public class SimApiOptions public class SimApiOptions
{ {
public bool EnableCors { get; set; } = true;
public bool EnableSimApiAuth { get; set; } = false; public bool EnableSimApiAuth { get; set; } = false;
public bool EnableSimApiDoc { get; set; } = true; public bool EnableSimApiDoc { get; set; } = true;
public bool EnableSimApiException { get; set; } = true; public bool EnableSimApiException { get; set; } = true;
+13
View File
@@ -27,6 +27,12 @@ namespace SimApi
builder.AddScoped<SimApiAuth>(); builder.AddScoped<SimApiAuth>();
} }
if (simApiOptions.EnableCors)
{
builder.AddCors(cors => cors.AddPolicy("any",
policy => { policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin(); }));
}
// 使用SimApiDoc // 使用SimApiDoc
if (simApiOptions.EnableSimApiDoc) if (simApiOptions.EnableSimApiDoc)
{ {
@@ -138,6 +144,7 @@ namespace SimApi
if (simApiOptions.EnableSimApiStorage) if (simApiOptions.EnableSimApiStorage)
{ {
builder.AddHttpContextAccessor();
builder.AddSingleton<SimApiStorage>(); builder.AddSingleton<SimApiStorage>();
} }
@@ -159,6 +166,12 @@ namespace SimApi
builder.UseForwardedHeaders(); builder.UseForwardedHeaders();
} }
if (options.EnableCors)
{
SimApiUtil.Log("开始配置Cors全部允许...");
builder.UseCors("any");
}
if (options.EnableSimApiAuth) if (options.EnableSimApiAuth)
{ {
SimApiUtil.Log("开始配置SimApiAuth..."); SimApiUtil.Log("开始配置SimApiAuth...");