diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-08-09 09:53:22 -0400 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2016-08-09 08:53:22 -0500 |
commit | 0afa28de0953ed528486a7d7ad6000f344624710 (patch) | |
tree | a31d1668aab355784547d1bc93ab3d8801ed2dd7 /api | |
parent | 09d98b486e8245ae84a452331e36e2978a6d01ab (diff) | |
download | chat-0afa28de0953ed528486a7d7ad6000f344624710.tar.gz chat-0afa28de0953ed528486a7d7ad6000f344624710.tar.bz2 chat-0afa28de0953ed528486a7d7ad6000f344624710.zip |
Changed autodetection of SiteURL (#3764)
* Changed autoconfiguration of SiteURL to be done on every request
* Added SiteURL to system console
Diffstat (limited to 'api')
-rw-r--r-- | api/context.go | 16 | ||||
-rw-r--r-- | api/post.go | 1 |
2 files changed, 12 insertions, 5 deletions
diff --git a/api/context.go b/api/context.go index 08f41aa6d..c0e6bf3b5 100644 --- a/api/context.go +++ b/api/context.go @@ -39,6 +39,7 @@ type Context struct { Err *model.AppError teamURLValid bool teamURL string + siteURL string T goi18n.TranslateFunc Locale string TeamId string @@ -141,10 +142,11 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isTokenFromQueryString = true } - // if the site url in the config isn't specified, infer if from this request and write it back to the config - if *utils.Cfg.ServiceSettings.SiteURL == "" { - *utils.Cfg.ServiceSettings.SiteURL = GetProtocol(r) + "://" + r.Host - utils.RegenerateClientConfig() + if *utils.Cfg.ServiceSettings.SiteURL != "" { + c.SetSiteURL(*utils.Cfg.ServiceSettings.SiteURL) + } else { + protocol := GetProtocol(r) + c.SetSiteURL(protocol + "://" + r.Host) } w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) @@ -439,6 +441,10 @@ func (c *Context) SetTeamURLFromSession() { } } +func (c *Context) SetSiteURL(url string) { + c.siteURL = url +} + func (c *Context) GetTeamURLFromTeam(team *model.Team) string { return c.GetSiteURL() + "/" + team.Name } @@ -454,7 +460,7 @@ func (c *Context) GetTeamURL() string { } func (c *Context) GetSiteURL() string { - return *utils.Cfg.ServiceSettings.SiteURL + return c.siteURL } func IsApiCall(r *http.Request) bool { diff --git a/api/post.go b/api/post.go index 0c7654df1..d32d1c6a5 100644 --- a/api/post.go +++ b/api/post.go @@ -458,6 +458,7 @@ func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel Err: nil, teamURLValid: c.teamURLValid, teamURL: c.teamURL, + siteURL: c.siteURL, T: c.T, Locale: c.Locale, TeamId: hook.TeamId, |