From 81f97ebc88be468f3cefecf8c850459d7eccc459 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 1 Mar 2016 14:17:29 -0300 Subject: [PATCH] Add default value to AllowCorsFrom setting --- api/context.go | 4 ++-- model/config.go | 7 ++++++- utils/config.go | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/context.go b/api/context.go index 3b97828517..91b11670b4 100644 --- a/api/context.go +++ b/api/context.go @@ -166,8 +166,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // All api response bodies will be JSON formatted by default w.Header().Set("Content-Type", "application/json") - if len(utils.Cfg.ServiceSettings.AllowCorsFrom) > 0 { - w.Header().Set("Access-Control-Allow-Origin", utils.Cfg.ServiceSettings.AllowCorsFrom) + if len(*utils.Cfg.ServiceSettings.AllowCorsFrom) > 0 { + w.Header().Set("Access-Control-Allow-Origin", *utils.Cfg.ServiceSettings.AllowCorsFrom) } if r.Method == "GET" { diff --git a/model/config.go b/model/config.go index a7d92c1013..82c51224e2 100644 --- a/model/config.go +++ b/model/config.go @@ -39,7 +39,7 @@ type ServiceSettings struct { EnableDeveloper *bool EnableSecurityFixAlert *bool EnableInsecureOutgoingConnections *bool - AllowCorsFrom string + AllowCorsFrom *string SessionLengthWebInDays *int SessionLengthMobileInDays *int SessionLengthSSOInDays *int @@ -378,6 +378,11 @@ func (o *Config) SetDefaults() { o.ServiceSettings.WebsocketSecurePort = new(int) *o.ServiceSettings.WebsocketSecurePort = 443 } + + if o.ServiceSettings.AllowCorsFrom == nil { + o.ServiceSettings.AllowCorsFrom = new(string) + *o.ServiceSettings.AllowCorsFrom = "" + } } func (o *Config) IsValid() *AppError { diff --git a/utils/config.go b/utils/config.go index 0a1d40db07..63906c3458 100644 --- a/utils/config.go +++ b/utils/config.go @@ -236,7 +236,7 @@ func getClientConfig(c *model.Config) map[string]string { props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) - props["AllowCorsFrom"] = c.ServiceSettings.AllowCorsFrom + props["AllowCorsFrom"] = *c.ServiceSettings.AllowCorsFrom return props }