From c4a3118e9f885e92bb9b7d882898e9a51fc3be69 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 2 Aug 2016 16:37:09 -0400 Subject: PLT-3408 Add SiteURL to config.json (#3692) * PLT-3408 Changed serverside code to get the service's URL from config.json * PLT-3408 Changed most clientside code to use the SiteURL config setting instead of window.location * PLT-3408 Changed default SiteURL to be autodetected --- api/context.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'api/context.go') diff --git a/api/context.go b/api/context.go index b26778711..6976feb8f 100644 --- a/api/context.go +++ b/api/context.go @@ -39,7 +39,6 @@ type Context struct { Err *model.AppError teamURLValid bool teamURL string - siteURL string T goi18n.TranslateFunc Locale string TeamId string @@ -139,8 +138,11 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isTokenFromQueryString = true } - protocol := GetProtocol(r) - c.SetSiteURL(protocol + "://" + r.Host) + // 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() + } w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v", model.CurrentVersion, utils.CfgLastModified)) @@ -180,7 +182,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.Path = r.URL.Path } else { splitURL := strings.Split(r.URL.Path, "/") - c.setTeamURL(protocol+"://"+r.Host+"/"+splitURL[1], true) + c.setTeamURL(c.GetSiteURL()+"/"+splitURL[1], true) c.Path = "/" + strings.Join(splitURL[2:], "/") } @@ -431,10 +433,6 @@ 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 } @@ -450,7 +448,7 @@ func (c *Context) GetTeamURL() string { } func (c *Context) GetSiteURL() string { - return c.siteURL + return *utils.Cfg.ServiceSettings.SiteURL } func IsApiCall(r *http.Request) bool { -- cgit v1.2.3-1-g7c22