MCPcopy Index your code
hub / github.com/ZenNotes/zennotes / serveIndexHTML

Method serveIndexHTML

apps/server/internal/httpserver/server.go:1011–1033  ·  view source on GitHub ↗

serveIndexHTML reads the SPA shell from the embedded bundle and returns it with a small runtime patch so the JS bundle knows which base path to use for API + WebSocket calls.

(w http.ResponseWriter)

Source from the content-addressed store, hash-verified

1009// returns it with a small runtime patch so the JS bundle knows which
1010// base path to use for API + WebSocket calls.
1011func (s *Server) serveIndexHTML(w http.ResponseWriter) {
1012 f, err := s.Static.Open("index.html")
1013 if err != nil {
1014 http.NotFound(w, nil)
1015 return
1016 }
1017 defer f.Close()
1018
1019 body, err := readAll(f)
1020 if err != nil {
1021 http.NotFound(w, nil)
1022 return
1023 }
1024
1025 basePath := s.currentConfig().BasePath
1026 if basePath != "" {
1027 body = injectBasePathHint(body, basePath)
1028 }
1029
1030 w.Header().Set("Content-Type", "text/html; charset=utf-8")
1031 w.Header().Set("Cache-Control", "no-cache")
1032 _, _ = w.Write(body)
1033}
1034
1035func readAll(f fs.File) ([]byte, error) {
1036 buf := make([]byte, 0, 4*1024)

Callers 1

serveStaticMethod · 0.95

Calls 4

currentConfigMethod · 0.95
readAllFunction · 0.85
injectBasePathHintFunction · 0.85
CloseMethod · 0.80

Tested by

no test coverage detected