Add default value to AllowCorsFrom setting

This commit is contained in:
Elias Nahum
2016-03-01 14:17:29 -03:00
parent ba6a38a7f6
commit 81f97ebc88
3 changed files with 9 additions and 4 deletions

View File

@@ -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" {

View File

@@ -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 {

View File

@@ -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
}