From d31b8aa054355e923bdc2a24196cb0351fcab37a Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Fri, 18 Mar 2022 14:59:40 -0500 Subject: [PATCH 1/2] Use custom favicon when viewing static files if it exists --- routers/web/web.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/routers/web/web.go b/routers/web/web.go index 9faa61e560560..c7e088999e1d5 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -99,6 +99,18 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), 301) }) + // the custom favicon should be seen when viewing files instead of the default one if it exists, + routes.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) { + faviconPath := "" + res, err := http.Get(path.Join(setting.StaticURLPrefix, "/assets/img/favicon.ico")) + if err != nil || res.StatusCode != 200 { + faviconPath = "/favicon.ico" + } else { + faviconPath = "/assets/img/favicon.ico" + } + http.Redirect(w, req, path.Join(setting.StaticURLPrefix, faviconPath), 301) + }) + common := []interface{}{} if setting.EnableGzip { From 17217ce2b4efde8ca39105f2c8eaf2248735d417 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sat, 19 Mar 2022 08:52:30 -0500 Subject: [PATCH 2/2] Redirect to a favicon PNG that always exists --- routers/web/web.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index c7e088999e1d5..6d2fbedacea2b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -99,16 +99,9 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), 301) }) - // the custom favicon should be seen when viewing files instead of the default one if it exists, + // redirect default favicon to the path of the custom favicon with a default as a fallback routes.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) { - faviconPath := "" - res, err := http.Get(path.Join(setting.StaticURLPrefix, "/assets/img/favicon.ico")) - if err != nil || res.StatusCode != 200 { - faviconPath = "/favicon.ico" - } else { - faviconPath = "/assets/img/favicon.ico" - } - http.Redirect(w, req, path.Join(setting.StaticURLPrefix, faviconPath), 301) + http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/favicon.png"), 301) }) common := []interface{}{}