mirror of https://github.com/minio/minio.git
fix: allow CORS to work by default (#16713)
This commit is contained in:
parent
4d708cebe9
commit
0ff931dc76
|
@ -516,7 +516,11 @@ func corsHandler(handler http.Handler) http.Handler {
|
||||||
|
|
||||||
return cors.New(cors.Options{
|
return cors.New(cors.Options{
|
||||||
AllowOriginFunc: func(origin string) bool {
|
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) {
|
if wildcard.MatchSimple(allowedOrigin, origin) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package api
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -193,6 +194,9 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
corsAllowOrigin := strings.Split(env.Get(EnvAPICorsAllowOrigin, kvs.Get(apiCorsAllowOrigin)), ",")
|
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)))
|
remoteTransportDeadline, err := time.ParseDuration(env.Get(EnvAPIRemoteTransportDeadline, kvs.GetWithDefault(apiRemoteTransportDeadline, DefaultKVS)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -203,14 +207,14 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||||
switch listQuorum {
|
switch listQuorum {
|
||||||
case "strict", "optimal", "reduced", "disk":
|
case "strict", "optimal", "reduced", "disk":
|
||||||
default:
|
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))
|
replicationPriority := env.Get(EnvAPIReplicationPriority, kvs.GetWithDefault(apiReplicationPriority, DefaultKVS))
|
||||||
switch replicationPriority {
|
switch replicationPriority {
|
||||||
case "slow", "fast", "auto":
|
case "slow", "fast", "auto":
|
||||||
default:
|
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)))
|
transitionWorkers, err := strconv.Atoi(env.Get(EnvAPITransitionWorkers, kvs.GetWithDefault(apiTransitionWorkers, DefaultKVS)))
|
||||||
|
@ -242,7 +246,6 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
disableODirect := env.Get(EnvAPIDisableODirect, kvs.Get(apiDisableODirect)) == config.EnableOn
|
disableODirect := env.Get(EnvAPIDisableODirect, kvs.Get(apiDisableODirect)) == config.EnableOn
|
||||||
|
|
||||||
gzipObjects := env.Get(EnvAPIGzipObjects, kvs.Get(apiGzipObjects)) == config.EnableOn
|
gzipObjects := env.Get(EnvAPIGzipObjects, kvs.Get(apiGzipObjects)) == config.EnableOn
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
|
|
Loading…
Reference in New Issue