Skip to content

Commit

Permalink
feat(knifehub.web): corsAllowHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Oct 20, 2024
1 parent 606bcd0 commit 9112877
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/KnifeHub.Web/Config/ConfigOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class SentryModel

public List<string> CorsWhiteList { get; set; }

public List<string> CorsAllowHeaders { get; set; }

public LogModel Log { get; set; }

public class LogModel
Expand Down
3 changes: 2 additions & 1 deletion src/KnifeHub.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public static void Main(string[] args)
// 解决发送json,复杂请求问题: https://blog.csdn.net/yangyiboshigou/article/details/78738228
// 解决方法: Access-Control-Allow-Headers: Content-Type
// 参考: https://www.cnblogs.com/jpfss/p/10102132.html
.WithHeaders("Content-Type");
//.WithHeaders("Content-Type");
.WithHeaders(configOptions.CorsAllowHeaders?.ToArray() ?? new string[] { "Content-Type" });
});
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/KnifeHub.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"KnifeHub": {
"AllowAllCors": false,
"CorsWhiteList": [ "http://127.0.0.1:5000", "http://localhost:5002" ],
"CorsAllowHeaders": [ "Content-Type", "x-fingerprint", "authorization" ],
"Sentry": {
"Enabled": true
},
"Log": {
"RetainedFileCountLimit": 31,
"RetainedFileTimeLimitDays": 31
}
}
}
1 change: 1 addition & 0 deletions src/KnifeHub.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"KnifeHub": {
"AllowAllCors": false,
"CorsWhiteList": [],
"CorsAllowHeaders": [],
"Sentry": {
"Enabled": true
},
Expand Down

0 comments on commit 9112877

Please sign in to comment.