summaryrefslogtreecommitdiffstats
path: root/web/web.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-09-15 08:51:46 -0400
committerGitHub <noreply@github.com>2017-09-15 08:51:46 -0400
commit2628022275ef64fde95545abe4634b4bd7177844 (patch)
tree25d451b81d720f44aa09b20389be7fbb75b7864e /web/web.go
parent2a6cd44f23e1b3207debaa73801f0c63a2c81126 (diff)
downloadchat-2628022275ef64fde95545abe4634b4bd7177844.tar.gz
chat-2628022275ef64fde95545abe4634b4bd7177844.tar.bz2
chat-2628022275ef64fde95545abe4634b4bd7177844.zip
PLT-7622 Improvements to server handling of webapp plugins (#7445)
* Improvements to server handling of webapp plugins * Fix newline * Update manifest function names
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/web/web.go b/web/web.go
index c883c750d..f74c73cde 100644
--- a/web/web.go
+++ b/web/web.go
@@ -26,12 +26,17 @@ func InitWeb() {
if *utils.Cfg.ServiceSettings.WebserverMode != "disabled" {
staticDir, _ := utils.FindDir(model.CLIENT_DIR)
l4g.Debug("Using client directory at %v", staticDir)
+
+ staticHandler := staticHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
+ pluginHandler := pluginHandler(http.StripPrefix("/static/plugins/", http.FileServer(http.Dir(staticDir+"plugins/"))))
+
if *utils.Cfg.ServiceSettings.WebserverMode == "gzip" {
- mainrouter.PathPrefix("/static/").Handler(gziphandler.GzipHandler(staticHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))))
- } else {
- mainrouter.PathPrefix("/static/").Handler(staticHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))))
+ staticHandler = gziphandler.GzipHandler(staticHandler)
+ pluginHandler = gziphandler.GzipHandler(pluginHandler)
}
+ mainrouter.PathPrefix("/static/plugins/").Handler(pluginHandler)
+ mainrouter.PathPrefix("/static/").Handler(staticHandler)
mainrouter.Handle("/{anything:.*}", api.AppHandlerIndependent(root)).Methods("GET")
}
}
@@ -47,6 +52,21 @@ func staticHandler(handler http.Handler) http.Handler {
})
}
+func pluginHandler(handler http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if *utils.Cfg.ServiceSettings.EnableDeveloper {
+ w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+ } else {
+ w.Header().Set("Cache-Control", "max-age=31556926, public")
+ }
+ if strings.HasSuffix(r.URL.Path, "/") {
+ http.NotFound(w, r)
+ return
+ }
+ handler.ServeHTTP(w, r)
+ })
+}
+
//map should be of minimum required browser version.
//var browsersNotSupported string = "MSIE/11;Internet Explorer/11;Safari/9;Chrome/43;Edge/15;Firefox/52"
//var browserMinimumSupported = [6]string{"MSIE/11", "Internet Explorer/11", "Safari/9", "Chrome/43", "Edge/15", "Firefox/52"}