Compare commits

..
3 Commits
Author SHA1 Message Date
xrain 9c939426ba fix logger 2022-08-05 02:33:47 +08:00
xrain e45cc4d28d fix logger 2022-08-05 02:20:27 +08:00
xrain 6023cf2eb0 fix default option, add option description 2022-06-29 03:03:51 +08:00
3 changed files with 64 additions and 11 deletions
+42 -4
View File
@@ -4,24 +4,62 @@ namespace SimApi.Configs
{ {
public class SimApiOptions public class SimApiOptions
{ {
public bool EnableCors { get; set; } = false; /// <summary>
/// 启用全部Cors,对于开发前后分离的时候很有用。
/// default: true
/// </summary>
public bool EnableCors { get; set; } = true;
/// <summary>
/// 启用SimapiAuth,一个简单的基于Header Token的认证方式。
/// default: false
/// </summary>
public bool EnableSimApiAuth { get; set; } = false; public bool EnableSimApiAuth { get; set; } = false;
/// <summary>
/// 启用在线文档,启用后 访问 /swagger 可以查看对应的api文档。
/// default: false
/// </summary>
public bool EnableSimApiDoc { get; set; } = false; public bool EnableSimApiDoc { get; set; } = false;
public bool EnableSimApiException { get; set; } = false; /// <summary>
/// 启用异常拦截,启用后,所有的异常将被通过json反馈。
/// default: true
/// </summary>
public bool EnableSimApiException { get; set; } = true;
/// <summary>
/// 开启S3兼容的存储系统。
/// default: false
/// </summary>
public bool EnableSimApiStorage { get; set; } = false; public bool EnableSimApiStorage { get; set; } = false;
public bool EnableForwardHeaders { get; set; } = false; /// <summary>
/// 开启ForwardHeaders,开启后可以透传负载均衡的Headers
/// default: true
/// </summary>
public bool EnableForwardHeaders { get; set; } = true;
public bool EnableLowerUrl { get; set; } = false; /// <summary>
/// 将所有的url都格式化为小写字母
/// default: true
/// </summary>
public bool EnableLowerUrl { get; set; } = true;
/// <summary>
/// 启用格式化的 Console Logger
/// default: false
/// </summary>
public bool EnableLogger { get; set; } = false; public bool EnableLogger { get; set; } = false;
/// <summary>
/// Swagger文档相关配置,需要启用 EnableSimApiDoc
/// </summary>
public SimApiDocOptions SimApiDocOptions { get; set; } = new SimApiDocOptions(); public SimApiDocOptions SimApiDocOptions { get; set; } = new SimApiDocOptions();
/// <summary>
/// S3兼容的存储系统配置,需要启用 EnableSimApiStorage
/// </summary>
public SimApiStorageOptions SimApiStorageOptions { get; set; } = new SimApiStorageOptions(); public SimApiStorageOptions SimApiStorageOptions { get; set; } = new SimApiStorageOptions();
+13
View File
@@ -2,10 +2,23 @@ namespace SimApi.Configs
{ {
public class SimApiStorageOptions public class SimApiStorageOptions
{ {
/// <summary>
/// S3 服务器入口地址
/// </summary>
public string Endpoint { get; set; } public string Endpoint { get; set; }
/// <summary>
/// S3 服务器文件访问地址
/// </summary>
public string ServeUrl { get; set; } public string ServeUrl { get; set; }
/// <summary>
/// S3服务 Bucket
/// </summary>
public string Bucket { get; set; } public string Bucket { get; set; }
public string AccessKey { get; set; } public string AccessKey { get; set; }
public string SecretKey { get; set; } public string SecretKey { get; set; }
} }
} }
+9 -7
View File
@@ -22,7 +22,14 @@ namespace SimApi
{ {
var simApiOptions = new SimApiOptions(); var simApiOptions = new SimApiOptions();
options?.Invoke(simApiOptions); options?.Invoke(simApiOptions);
if (simApiOptions.EnableLogger)
{
builder.AddLogging(logger =>
{
logger.ClearProviders();
logger.AddProvider(new SimApiLoggerProvider());
});
}
// 是否使用 AUTH // 是否使用 AUTH
if (simApiOptions.EnableSimApiAuth) if (simApiOptions.EnableSimApiAuth)
{ {
@@ -190,13 +197,8 @@ namespace SimApi
public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder) public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder)
{ {
var options = builder.ApplicationServices.GetRequiredService<SimApiOptions>(); var options = builder.ApplicationServices.GetRequiredService<SimApiOptions>();
if (options.EnableLogger)
{
builder.ApplicationServices.GetRequiredService<ILoggerFactory>()
.AddProvider(new SimApiLoggerProvider());
}
var logger = builder.ApplicationServices.GetRequiredService<ILogger<SimApiLogger>>(); var logger = builder.ApplicationServices.GetRequiredService<ILogger<SimApiOptions>>();
if (options.EnableForwardHeaders) if (options.EnableForwardHeaders)
{ {