Skip to content

Commit 6e60e1a

Browse files
authored
fix: panic in the config (#268)
On-behalf-of: @SAP [email protected] Signed-off-by: Artem Shcherbatiuk <[email protected]>
1 parent 1f81aa9 commit 6e60e1a

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func initConfig() {
6767
v.SetDefault("gateway-handler-graphiql", true)
6868
// Gateway CORS
6969
v.SetDefault("gateway-cors-enabled", false)
70-
v.SetDefault("gateway-cors-allowed-origins", []string{"*"})
71-
v.SetDefault("gateway-cors-allowed-headers", []string{"*"})
70+
v.SetDefault("gateway-cors-allowed-origins", "*")
71+
v.SetDefault("gateway-cors-allowed-headers", "*")
7272
}
7373

7474
func Execute() {

common/config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type Config struct {
2222
} `mapstructure:",squash"`
2323

2424
Cors struct {
25-
Enabled bool `mapstructure:"gateway-cors-enabled"`
26-
AllowedOrigins []string `mapstructure:"gateway-cors-allowed-origins"`
27-
AllowedHeaders []string `mapstructure:"gateway-cors-allowed-headers"`
25+
Enabled bool `mapstructure:"gateway-cors-enabled"`
26+
AllowedOrigins string `mapstructure:"gateway-cors-allowed-origins"`
27+
AllowedHeaders string `mapstructure:"gateway-cors-allowed-headers"`
2828
} `mapstructure:",squash"`
2929
} `mapstructure:",squash"`
3030
}

gateway/manager/export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
func NewManagerForTest() *Service {
1111
cfg := appConfig.Config{}
1212
cfg.Gateway.Cors.Enabled = true
13-
cfg.Gateway.Cors.AllowedOrigins = []string{"*"}
14-
cfg.Gateway.Cors.AllowedHeaders = []string{"Authorization"}
13+
cfg.Gateway.Cors.AllowedOrigins = "*"
14+
cfg.Gateway.Cors.AllowedHeaders = "Authorization"
1515

1616
s := &Service{
1717
AppCfg: cfg,

gateway/manager/handler.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7979

8080
func (s *Service) handleCORS(w http.ResponseWriter, r *http.Request) bool {
8181
if s.AppCfg.Gateway.Cors.Enabled {
82-
allowedOrigins := strings.Join(s.AppCfg.Gateway.Cors.AllowedOrigins, ",")
83-
allowedHeaders := strings.Join(s.AppCfg.Gateway.Cors.AllowedHeaders, ",")
84-
w.Header().Set("Access-Control-Allow-Origin", allowedOrigins)
85-
w.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
82+
w.Header().Set("Access-Control-Allow-Origin", s.AppCfg.Gateway.Cors.AllowedOrigins)
83+
w.Header().Set("Access-Control-Allow-Headers", s.AppCfg.Gateway.Cors.AllowedHeaders)
8684
// setting cors allowed methods is not needed for this service,
8785
// as all graphql methods are part of the cors safelisted methods
8886
// https://fetch.spec.whatwg.org/#cors-safelisted-method

0 commit comments

Comments
 (0)