Compare commits

...
3 Commits
Author SHA1 Message Date
xrain 8b4d551af8 storage add client 2021-06-07 15:24:22 +08:00
xrain 3445531972 add cors 2021-06-05 14:33:59 +08:00
xrain 2268ad0c8c add cors 2021-06-05 14:30:52 +08:00
3 changed files with 16 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;
+3
View File
@@ -10,6 +10,9 @@ namespace SimApi.Helpers
public class SimApiStorage public class SimApiStorage
{ {
private MinioClient Mc { get; } private MinioClient Mc { get; }
public MinioClient Client => Mc;
private string ServeUrl { get; } private string ServeUrl { get; }
private string Bucket { get; } private string Bucket { get; }
private IHttpContextAccessor HttpContextAccessor { get; } private IHttpContextAccessor HttpContextAccessor { get; }
+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...");