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 /web/web.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 'web/web.go')
-rw-r--r-- | web/web.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/web/web.go b/web/web.go index 5c1836818..479f439fb 100644 --- a/web/web.go +++ b/web/web.go @@ -6,6 +6,7 @@ package web import ( "fmt" "net/http" + "path" "strings" "github.com/avct/uasurfer" @@ -60,17 +61,19 @@ func Handle404(a *app.App, w http.ResponseWriter, r *http.Request) { mlog.Debug(fmt.Sprintf("%v: code=404 ip=%v", r.URL.Path, utils.GetIpAddress(r))) - if IsApiCall(r) { + if IsApiCall(a, r) { w.WriteHeader(err.StatusCode) err.DetailedError = "There doesn't appear to be an api call for the url='" + r.URL.Path + "'. Typo? are you missing a team_id or user_id as part of the url?" w.Write([]byte(err.ToJson())) } else { - utils.RenderWebAppError(w, r, err, a.AsymmetricSigningKey()) + utils.RenderWebAppError(a.Config(), w, r, err, a.AsymmetricSigningKey()) } } -func IsApiCall(r *http.Request) bool { - return strings.Index(r.URL.Path, "/api/") == 0 +func IsApiCall(a *app.App, r *http.Request) bool { + subpath, _ := utils.GetSubpathFromConfig(a.Config()) + + return strings.Index(r.URL.Path, path.Join(subpath, "api")+"/") == 0 } func ReturnStatusOK(w http.ResponseWriter) { |