fix: 修复 API 密钥逻辑,确保正确设置和使用 Fscan-API-SECRET 头

This commit is contained in:
tongque 2025-04-22 13:01:54 +08:00
parent a30cd12249
commit 2d9ea9c1d3

View File

@ -21,7 +21,9 @@ func StartApiServer() error {
if Common.ApiAddr == "" {
return nil
}
if Common.SecretKey == "" {
if Common.SecretKey != "" {
internalSecretKey = Common.SecretKey
} else {
internalSecretKey = time.Now().Format("20060102150405")
}
@ -77,7 +79,7 @@ func applyMiddlewares(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, Fscan-API-SECRET")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)