|
@@ -18,6 +18,7 @@ using FccLite.Web.Repositories.FccOrderInfo;
|
|
|
using FccLite.Web.Services.FccMachineInfo;
|
|
|
using FccLite.Web.Repositories.FccMachineInfo;
|
|
|
using OfficeOpenXml;
|
|
|
+using System.Text.Json;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
// 自动加载 appsettings.json 和 appsettings.{Environment}.json
|
|
@@ -87,8 +88,38 @@ builder.Services.AddSwaggerGen(c =>
|
|
|
instantiateResults.Where(r => r.Succeed).Select(r => r.ProcessorInstance),
|
|
|
"Main starting");
|
|
|
}
|
|
|
+
|
|
|
+builder.Services.AddControllers()
|
|
|
+ .AddJsonOptions(options =>
|
|
|
+ {
|
|
|
+ options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; // 支持 camelCase
|
|
|
+ options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
|
|
|
+ });
|
|
|
+// 添加CORS服务,并允许所有来源
|
|
|
+builder.Services.AddCors(options =>
|
|
|
+{
|
|
|
+ options.AddPolicy("AllowAll", policy =>
|
|
|
+ {
|
|
|
+ policy.AllowAnyOrigin() // 允许所有来源(生产环境应指定具体域名)
|
|
|
+ .AllowAnyMethod() // 允许所有 HTTP 方法
|
|
|
+ .AllowAnyHeader() // 允许所有请求头
|
|
|
+ .SetPreflightMaxAge(TimeSpan.FromSeconds(86400)); // 预检请求缓存时间
|
|
|
+ });
|
|
|
+});
|
|
|
var app = builder.Build();
|
|
|
|
|
|
+//跨域
|
|
|
+app.UseCors("AllowAll");
|
|
|
+app.Use(async (context, next) =>
|
|
|
+{
|
|
|
+ context.Response.Headers["Referrer-Policy"] = "strict-origin-when-cross-origin";
|
|
|
+ context.Request.EnableBuffering(); // 允许多次读取
|
|
|
+ var requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
|
|
|
+ Console.WriteLine($"Request Body: {requestBody}");
|
|
|
+ context.Request.Body.Position = 0; // 重置流的位置
|
|
|
+ await next();
|
|
|
+});
|
|
|
+
|
|
|
//controller
|
|
|
app.UseHttpsRedirection();
|
|
|
app.UseAuthorization();
|