diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-06-21 14:31:51 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-06-21 11:31:51 -0700 |
commit | dd35ad43caab407cc70ef3b153b3f94d57242ed9 (patch) | |
tree | 67afe0fb6ad784e740d8b2a99d5de5c04342661c /utils/api.go | |
parent | 46f969e5ddbe4404dbc82dbe78ab2fa101d9922e (diff) | |
download | chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.tar.gz chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.tar.bz2 chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.zip |
MM-10370: serve subpath (#8968)
* factor out GetSubpathFromConfig
* mv web/subpath.go to utils/subpath.go
* serve up web, api and ws on /subpath if configured
* pass config to utils.RenderWeb(App)?Error
This allows the methods to extract the configured subpath and redirect
to the appropriate `/subpath/error` handler.
* ensure GetSubpathFromConfig returns trailing slashes deterministically
* fix error 404 handling
* redirect /subpath to /subpath/
This is necessary for the static handler to match, otherwise none of the
registered routes find anything. This also makes it no longer necessary
to add trailing slashes in the root router.
Diffstat (limited to 'utils/api.go')
-rw-r--r-- | utils/api.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/utils/api.go b/utils/api.go index b5e490eb7..d14f316b6 100644 --- a/utils/api.go +++ b/utils/api.go @@ -11,6 +11,7 @@ import ( "html/template" "net/http" "net/url" + "path" "strings" "github.com/mattermost/mattermost-server/model" @@ -35,24 +36,26 @@ func OriginChecker(allowedOrigins string) func(*http.Request) bool { } } -func RenderWebAppError(w http.ResponseWriter, r *http.Request, err *model.AppError, s crypto.Signer) { - RenderWebError(w, r, err.StatusCode, url.Values{ +func RenderWebAppError(config *model.Config, w http.ResponseWriter, r *http.Request, err *model.AppError, s crypto.Signer) { + RenderWebError(config, w, r, err.StatusCode, url.Values{ "message": []string{err.Message}, }, s) } -func RenderWebError(w http.ResponseWriter, r *http.Request, status int, params url.Values, s crypto.Signer) { +func RenderWebError(config *model.Config, w http.ResponseWriter, r *http.Request, status int, params url.Values, s crypto.Signer) { queryString := params.Encode() + subpath, _ := GetSubpathFromConfig(config) + h := crypto.SHA256 sum := h.New() - sum.Write([]byte("/error?" + queryString)) + sum.Write([]byte(path.Join(subpath, "error") + "?" + queryString)) signature, err := s.Sign(rand.Reader, sum.Sum(nil), h) if err != nil { http.Error(w, "", http.StatusInternalServerError) return } - destination := "/error?" + queryString + "&s=" + base64.URLEncoding.EncodeToString(signature) + destination := path.Join(subpath, "error") + "?" + queryString + "&s=" + base64.URLEncoding.EncodeToString(signature) if status >= 300 && status < 400 { http.Redirect(w, r, destination, status) |