From 7d66461175c2e612c4b2e470df9f6baebc0ff43e Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Fri, 23 Jan 2026 13:58:23 +0900 Subject: [PATCH] appview/state: support `/favicon.ico` apps like pdsls.dev expects favicon to exist in well-known path Not including `favicon.svg` as I don't think apps expecting static favicon path will care about svg icons. Signed-off-by: Seongmin Lee --- appview/pages/pages.go | 29 +++++++++++++++++++++++++++++ appview/state/router.go | 1 + 2 files changed, 30 insertions(+) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index aa579bc5..bd316831 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1436,6 +1436,35 @@ func (p *Pages) Static() http.Handler { return Cache(http.StripPrefix("/static/", http.FileServer(http.FS(sub)))) } +func (p *Pages) StaticFile(path string) http.Handler { + if p.dev { + filePath := filepath.Join("appview/pages/static", path) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, filePath) + }) + } + sub, err := fs.Sub(p.embedFS, "static") + if err != nil { + p.logger.Error("no static dir found? that's crazy", "err", err) + panic(err) + } + fsys := http.FS(sub) + return Cache(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + f, err := fsys.Open(path) + if err != nil { + http.NotFound(w, r) + return + } + defer f.Close() + stat, err := f.Stat() + if err != nil { + http.NotFound(w, r) + return + } + http.ServeContent(w, r, stat.Name(), stat.ModTime(), f.(io.ReadSeeker)) + })) +} + func Cache(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { path := strings.Split(r.URL.Path, "?")[0] diff --git a/appview/state/router.go b/appview/state/router.go index cdbda927..5d1d4196 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -32,6 +32,7 @@ func (s *State) Router() http.Handler { s.pages, ) + router.Get("/favicon.ico", s.pages.StaticFile("logos/dolly.ico").ServeHTTP) router.Get("/pwa-manifest.json", s.WebAppManifest) router.Get("/robots.txt", s.RobotsTxt) -- 2.51.2