Compare commits

..
1 Commits
Author SHA1 Message Date
xrain 2268ad0c8c add cors 2021-06-05 14:30:52 +08:00
2 changed files with 15 additions and 2 deletions
+3 -2
View File
@@ -4,14 +4,15 @@ 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;
public bool EnableSimApiStorage { get; set; } = false; public bool EnableSimApiStorage { get; set; } = false;
public bool EnableForwardHeaders { get; set; } = true; public bool EnableForwardHeaders { get; set; } = true;
public bool EnableLowerUrl { get; set; } = true; public bool EnableLowerUrl { get; set; } = true;
public SimApiDocOptions SimApiDocOptions { get; set; } = new SimApiDocOptions(); public SimApiDocOptions SimApiDocOptions { get; set; } = new();
public SimApiStorageOptions SimApiStorageOptions { get; set; } = new SimApiStorageOptions(); public SimApiStorageOptions SimApiStorageOptions { get; set; } = new();
public void ConfigureSimApiDoc(Action<SimApiDocOptions> options = null) public void ConfigureSimApiDoc(Action<SimApiDocOptions> options = null)
+12
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)
{ {
@@ -160,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...");