diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/web.go | 26 |
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"} |