From 2628022275ef64fde95545abe4634b4bd7177844 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 15 Sep 2017 08:51:46 -0400 Subject: PLT-7622 Improvements to server handling of webapp plugins (#7445) * Improvements to server handling of webapp plugins * Fix newline * Update manifest function names --- web/web.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'web/web.go') 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"} -- cgit v1.2.3-1-g7c22