--- Static / PWA fallback ---
(w http.ResponseWriter, r *http.Request)
| 974 | // --- Static / PWA fallback --- |
| 975 | |
| 976 | func (s *Server) serveStatic(w http.ResponseWriter, r *http.Request) { |
| 977 | // chi's Mount routes by a stripped path but leaves r.URL.Path intact, |
| 978 | // so under a base-path deploy this still carries the prefix (e.g. |
| 979 | // "/zennotes/assets/app.css"). Trim it before resolving against the |
| 980 | // embedded bundle, otherwise every asset misses and falls back to |
| 981 | // index.html with a text/html MIME type (issue #58). |
| 982 | urlPath := r.URL.Path |
| 983 | if basePath := s.currentConfig().BasePath; basePath != "" { |
| 984 | urlPath = strings.TrimPrefix(urlPath, basePath) |
| 985 | } |
| 986 | urlPath = strings.TrimPrefix(urlPath, "/") |
| 987 | if urlPath == "" { |
| 988 | urlPath = "index.html" |
| 989 | } |
| 990 | f, err := s.Static.Open(urlPath) |
| 991 | if err != nil { |
| 992 | // SPA fallback: serve index.html for unknown paths. |
| 993 | s.serveIndexHTML(w) |
| 994 | return |
| 995 | } |
| 996 | defer f.Close() |
| 997 | if urlPath == "index.html" { |
| 998 | s.serveIndexHTML(w) |
| 999 | return |
| 1000 | } |
| 1001 | ext := strings.ToLower(filepath.Ext(urlPath)) |
| 1002 | if t := mime.TypeByExtension(ext); t != "" { |
| 1003 | w.Header().Set("Content-Type", t) |
| 1004 | } |
| 1005 | _, _ = copyReadSeeker(w, f) |
| 1006 | } |
| 1007 | |
| 1008 | // serveIndexHTML reads the SPA shell from the embedded bundle and |
| 1009 | // returns it with a small runtime patch so the JS bundle knows which |
nothing calls this directly
no test coverage detected