feat: 优化CORS配置支持通配符和代码格式化
- 支持CORS配置使用通配符"*"允许所有来源访问 - 优化CORS策略配置逻辑,区分通配符和具体域名处理 - 格式化代码,移除多余空行和统一代码风格 - 修复Hangfire配置中的变量赋值格式 - 更新默认CORS配置为通配符模式
This commit is contained in:
@@ -56,14 +56,12 @@ namespace Yi.Abp.Web
|
|||||||
typeof(YiAbpApplicationModule),
|
typeof(YiAbpApplicationModule),
|
||||||
typeof(AbpAspNetCoreMultiTenancyModule),
|
typeof(AbpAspNetCoreMultiTenancyModule),
|
||||||
typeof(AbpAspNetCoreMvcModule),
|
typeof(AbpAspNetCoreMvcModule),
|
||||||
|
|
||||||
typeof(AbpSwashbuckleModule),
|
typeof(AbpSwashbuckleModule),
|
||||||
typeof(AbpAspNetCoreSerilogModule),
|
typeof(AbpAspNetCoreSerilogModule),
|
||||||
typeof(AbpAuditingModule),
|
typeof(AbpAuditingModule),
|
||||||
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
|
||||||
typeof(YiFrameworkAspNetCoreModule),
|
typeof(YiFrameworkAspNetCoreModule),
|
||||||
typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule),
|
typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule),
|
||||||
|
|
||||||
typeof(YiFrameworkBackgroundWorkersHangfireModule),
|
typeof(YiFrameworkBackgroundWorkersHangfireModule),
|
||||||
typeof(AbpAutofacModule)
|
typeof(AbpAutofacModule)
|
||||||
)]
|
)]
|
||||||
@@ -108,12 +106,9 @@ namespace Yi.Abp.Web
|
|||||||
//本地开发环境,可以禁用作业执行
|
//本地开发环境,可以禁用作业执行
|
||||||
if (host.IsDevelopment())
|
if (host.IsDevelopment())
|
||||||
{
|
{
|
||||||
Configure<AbpBackgroundWorkerOptions> (options =>
|
Configure<AbpBackgroundWorkerOptions>(options => { options.IsEnabled = false; });
|
||||||
{
|
|
||||||
options.IsEnabled = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//请求日志
|
//请求日志
|
||||||
Configure<AbpAuditingOptions>(options =>
|
Configure<AbpAuditingOptions>(options =>
|
||||||
{
|
{
|
||||||
@@ -172,18 +167,27 @@ namespace Yi.Abp.Web
|
|||||||
{
|
{
|
||||||
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
||||||
{
|
{
|
||||||
|
var corsOrigins = configuration["App:CorsOrigins"]!;
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.WithOrigins(
|
.WithAbpExposedHeaders()
|
||||||
configuration["App:CorsOrigins"]!
|
.AllowAnyHeader()
|
||||||
|
.AllowAnyMethod();
|
||||||
|
|
||||||
|
if (corsOrigins == "*")
|
||||||
|
{
|
||||||
|
builder.AllowAnyOrigin();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.WithOrigins(corsOrigins
|
||||||
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(o => o.RemovePostFix("/"))
|
.Select(o => o.RemovePostFix("/"))
|
||||||
.ToArray()
|
.ToArray())
|
||||||
)
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||||
.WithAbpExposedHeaders()
|
.AllowCredentials();
|
||||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
}
|
||||||
.AllowAnyHeader()
|
|
||||||
.AllowAnyMethod()
|
|
||||||
.AllowCredentials();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -200,17 +204,17 @@ namespace Yi.Abp.Web
|
|||||||
|
|
||||||
//配置Hangfire定时任务存储,开启redis后,优先使用redis
|
//配置Hangfire定时任务存储,开启redis后,优先使用redis
|
||||||
var redisConfiguration = configuration["Redis:Configuration"];
|
var redisConfiguration = configuration["Redis:Configuration"];
|
||||||
context.Services.AddHangfire(config=>
|
context.Services.AddHangfire(config =>
|
||||||
{
|
{
|
||||||
var redisEnabled=configuration.GetSection("Redis").GetValue<bool>("IsEnabled");
|
var redisEnabled = configuration.GetSection("Redis").GetValue<bool>("IsEnabled");
|
||||||
if (redisEnabled)
|
if (redisEnabled)
|
||||||
{
|
{
|
||||||
var jobDb=configuration.GetSection("Redis").GetValue<int>("JobDb");
|
var jobDb = configuration.GetSection("Redis").GetValue<int>("JobDb");
|
||||||
config.UseRedisStorage(
|
config.UseRedisStorage(
|
||||||
ConnectionMultiplexer.Connect(redisConfiguration),
|
ConnectionMultiplexer.Connect(redisConfiguration),
|
||||||
new RedisStorageOptions()
|
new RedisStorageOptions()
|
||||||
{
|
{
|
||||||
Db =jobDb,
|
Db = jobDb,
|
||||||
InvisibilityTimeout = TimeSpan.FromHours(1), //JOB允许执行1小时
|
InvisibilityTimeout = TimeSpan.FromHours(1), //JOB允许执行1小时
|
||||||
Prefix = "Yi:HangfireJob:"
|
Prefix = "Yi:HangfireJob:"
|
||||||
}).WithJobExpirationTimeout(TimeSpan.FromHours(1));
|
}).WithJobExpirationTimeout(TimeSpan.FromHours(1));
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
//应用启动
|
//应用启动
|
||||||
"App": {
|
"App": {
|
||||||
"SelfUrl": "http://*:19001",
|
"SelfUrl": "http://*:19001",
|
||||||
"CorsOrigins": "http://localhost:19001;http://localhost:18000;vscode-file://vscode-app;https://web.chatboxai.app;capacitor://localhost;http://codegeex;https://yxai.chat"
|
"CorsOrigins": "*"
|
||||||
},
|
},
|
||||||
//配置
|
//配置
|
||||||
"Settings": {
|
"Settings": {
|
||||||
|
|||||||
Reference in New Issue
Block a user