Skip to content

Commit

Permalink
fix: allow CORS to work by default (minio#16713)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Feb 27, 2023
1 parent 4d708ce commit 0ff931d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/api-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ func corsHandler(handler http.Handler) http.Handler {

return cors.New(cors.Options{
AllowOriginFunc: func(origin string) bool {
for _, allowedOrigin := range globalAPIConfig.getCorsAllowOrigins() {
allowedOrigins := globalAPIConfig.getCorsAllowOrigins()
if len(allowedOrigins) == 0 {
allowedOrigins = []string{"*"}
}
for _, allowedOrigin := range allowedOrigins {
if wildcard.MatchSimple(allowedOrigin, origin) {
return true
}
Expand Down
9 changes: 6 additions & 3 deletions internal/config/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -193,6 +194,9 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
}

corsAllowOrigin := strings.Split(env.Get(EnvAPICorsAllowOrigin, kvs.Get(apiCorsAllowOrigin)), ",")
if len(corsAllowOrigin) == 0 {
corsAllowOrigin = []string{"*"} // defaults to '*'
}

remoteTransportDeadline, err := time.ParseDuration(env.Get(EnvAPIRemoteTransportDeadline, kvs.GetWithDefault(apiRemoteTransportDeadline, DefaultKVS)))
if err != nil {
Expand All @@ -203,14 +207,14 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
switch listQuorum {
case "strict", "optimal", "reduced", "disk":
default:
return cfg, errors.New("invalid value for list strict quorum")
return cfg, fmt.Errorf("invalid value %v for list_quorum", listQuorum)
}

replicationPriority := env.Get(EnvAPIReplicationPriority, kvs.GetWithDefault(apiReplicationPriority, DefaultKVS))
switch replicationPriority {
case "slow", "fast", "auto":
default:
return cfg, errors.New("invalid value for replication priority")
return cfg, fmt.Errorf("invalid value %v for replication_priority", replicationPriority)
}

transitionWorkers, err := strconv.Atoi(env.Get(EnvAPITransitionWorkers, kvs.GetWithDefault(apiTransitionWorkers, DefaultKVS)))
Expand Down Expand Up @@ -242,7 +246,6 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
}

disableODirect := env.Get(EnvAPIDisableODirect, kvs.Get(apiDisableODirect)) == config.EnableOn

gzipObjects := env.Get(EnvAPIGzipObjects, kvs.Get(apiGzipObjects)) == config.EnableOn

return Config{
Expand Down

0 comments on commit 0ff931d

Please sign in to comment.