Files
mattermost/web/web.go

67 lines
1.9 KiB
Go
Raw Normal View History

// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
2015-06-14 23:53:32 -08:00
// See License.txt for license information.
package web
import (
2016-02-08 07:26:10 -05:00
"net/http"
"strings"
2016-03-16 23:00:33 -04:00
"github.com/NYTimes/gziphandler"
2016-01-11 09:12:51 -06:00
l4g "github.com/alecthomas/log4go"
2015-06-14 23:53:32 -08:00
"github.com/mattermost/platform/api"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"github.com/mssola/user_agent"
)
2016-03-14 08:50:46 -04:00
const (
CLIENT_DIR = "webapp/dist"
)
2015-06-14 23:53:32 -08:00
func InitWeb() {
l4g.Debug(utils.T("web.init.debug"))
2015-06-14 23:53:32 -08:00
mainrouter := api.Srv.Router
2016-03-16 23:00:33 -04:00
if *utils.Cfg.ServiceSettings.WebserverMode != "disabled" {
staticDir := utils.FindDir(CLIENT_DIR)
l4g.Debug("Using client directory at %v", staticDir)
if *utils.Cfg.ServiceSettings.WebserverMode == "gzip" {
mainrouter.PathPrefix("/static/").Handler(gziphandler.GzipHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))))
} else {
mainrouter.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
}
2016-03-16 23:00:33 -04:00
mainrouter.Handle("/{anything:.*}", api.AppHandlerIndependent(root)).Methods("GET")
}
2015-06-14 23:53:32 -08:00
}
var browsersNotSupported string = "MSIE/8;MSIE/9;MSIE/10;Internet Explorer/8;Internet Explorer/9;Internet Explorer/10;Safari/7;Safari/8"
2015-06-14 23:53:32 -08:00
func CheckBrowserCompatability(c *api.Context, r *http.Request) bool {
ua := user_agent.New(r.UserAgent())
bname, bversion := ua.Browser()
browsers := strings.Split(browsersNotSupported, ";")
for _, browser := range browsers {
version := strings.Split(browser, "/")
if strings.HasPrefix(bname, version[0]) && strings.HasPrefix(bversion, version[1]) {
c.Err = model.NewLocAppError("CheckBrowserCompatability", "web.check_browser_compatibility.app_error", nil, "")
2015-06-14 23:53:32 -08:00
return false
}
}
return true
}
func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
if !CheckBrowserCompatability(c, r) {
return
}
2016-03-14 08:50:46 -04:00
http.ServeFile(w, r, utils.FindDir(CLIENT_DIR)+"root.html")
}