diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
index f897c82..b84b7b3 100644
--- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj
+++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
index 8deaacd..ff5b99b 100644
--- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
+++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
@@ -6,8 +6,12 @@ using Fake.Autofac;
using Fake.Modularity;
using InterfaceForward.Application;
using InterfaceForward.Application.Filters;
+using InterfaceForward.Domain.Shared;
using InterfaceForward.Domain.Shared.Helpers;
+using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.OpenApi.Models;
+using Swashbuckle.AspNetCore.SwaggerGen;
namespace InterfaceForward.Api;
@@ -36,12 +40,35 @@ public class InterfaceForwardApiModule : FakeModule
{
options.SerializerSettings.ContractResolver =
new Newtonsoft.Json.Serialization.
- CamelCasePropertyNamesContractResolver(); //.DefaultContractResolver();
+ CamelCasePropertyNamesContractResolver(); // 首字母小写(驼峰样式)
options.SerializerSettings.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
options.SerializerSettings.Converters.Add(new LongJsonConverter());
});
- services.AddFakeSwaggerGen()
+ services.AddFakeSwaggerGen(options =>
+ {
+ options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
+ {
+ Description = "JWT授权数据将在请求头中进行传输,在下方输入Bearer {token} 即可,注意两者之间有空格",
+ Name = "Authorization",
+ In = ParameterLocation.Header,
+ Type = SecuritySchemeType.ApiKey
+ });
+ options.AddSecurityRequirement(new OpenApiSecurityRequirement
+ {
+ {
+ new OpenApiSecurityScheme
+ {
+ Reference = new OpenApiReference()
+ {
+ Id = "Bearer",
+ Type = ReferenceType.SecurityScheme
+ }
+ },
+ []
+ }
+ });
+ })
.AddFakeExceptionFilter()
.AddFakeValidationActionFilter()
.AddFakeAspNetCoreAuditing()
@@ -57,6 +84,15 @@ public class InterfaceForwardApiModule : FakeModule
.AllowCredentials();
});
});
+
+ //Nginx代理的话获取真实IP
+ services.Configure(options =>
+ {
+ options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
+ //新增如下两行
+ options.KnownNetworks.Clear();
+ options.KnownProxies.Clear();
+ });
}
public override void ConfigureApplication(ApplicationConfigureContext context)
@@ -73,7 +109,7 @@ public class InterfaceForwardApiModule : FakeModule
// Add Aspire default endpoints.
app.MapDefaultEndpoints();
- app.MapControllers();
+
// Configure the HTTP request pipeline.
app.UseFakeSwagger();
@@ -81,6 +117,12 @@ public class InterfaceForwardApiModule : FakeModule
app.UseCors(DefaultCorsPolicyName);
+ app.UseAuthentication();
+ app.UseAuthorization();
+ app.UseForwardedHeaders();//Nginx代理的话获取真实IP
+
+ app.MapControllers();
+
LogHelper.Info("Application started", true);
}
diff --git a/src/InterfaceForward.Application/InterfaceForward.Application.csproj b/src/InterfaceForward.Application/InterfaceForward.Application.csproj
index 5e0ca19..393af4d 100644
--- a/src/InterfaceForward.Application/InterfaceForward.Application.csproj
+++ b/src/InterfaceForward.Application/InterfaceForward.Application.csproj
@@ -17,9 +17,9 @@
-
-
-
+
+
+
diff --git a/src/InterfaceForward.Api/DateTimeJsonConverter.cs b/src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs
similarity index 95%
rename from src/InterfaceForward.Api/DateTimeJsonConverter.cs
rename to src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs
index b2d273e..1a41ecf 100644
--- a/src/InterfaceForward.Api/DateTimeJsonConverter.cs
+++ b/src/InterfaceForward.Domain.Shared/DateTimeJsonConverter.cs
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
-namespace InterfaceForward.Api;
+namespace InterfaceForward.Domain.Shared;
public class DateTimeJsonConverter: JsonConverter
{
diff --git a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
index c6542f7..e7c0e9e 100644
--- a/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
+++ b/src/InterfaceForward.Domain.Shared/InterfaceForward.Domain.Shared.csproj
@@ -11,6 +11,6 @@
-
+
diff --git a/src/InterfaceForward.Api/LongJsonConverter.cs b/src/InterfaceForward.Domain.Shared/LongJsonConverter.cs
similarity index 94%
rename from src/InterfaceForward.Api/LongJsonConverter.cs
rename to src/InterfaceForward.Domain.Shared/LongJsonConverter.cs
index 72ad706..40c8e42 100644
--- a/src/InterfaceForward.Api/LongJsonConverter.cs
+++ b/src/InterfaceForward.Domain.Shared/LongJsonConverter.cs
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
-namespace InterfaceForward.Api;
+namespace InterfaceForward.Domain.Shared;
public class LongJsonConverter : JsonConverter
{
diff --git a/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj b/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj
index e2ba9dc..b4fa23e 100644
--- a/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj
+++ b/src/InterfaceForward.Repositories/InterfaceForward.Repositories.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs b/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs
index 6c54ac9..8e2439b 100644
--- a/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs
+++ b/src/InterfaceForward.Repositories/Log/Entitys/LogIndex.cs
@@ -1,5 +1,7 @@
-using InterfaceForward.Repositories.Log.ES;
+using InterfaceForward.Domain.Shared;
+using InterfaceForward.Repositories.Log.ES;
using Nest;
+using Newtonsoft.Json;
namespace InterfaceForward.Repositories.Log.Entitys;
@@ -14,6 +16,7 @@ public class LogIndex : IdBaseIndex
///
/// 请求时间
///
+ [JsonConverter(typeof(DateTimeJsonConverter), "yyyy-MM-dd HH:mm:ss fff")]
public DateTime RequestTime { get; set; }
///