MCPcopy Create free account
hub / github.com/driangle/taskmd / buildIndexHTML

Method buildIndexHTML

apps/cli/internal/web/server.go:199–222  ·  view source on GitHub ↗

buildIndexHTML reads index.html and injects the initial config as a script tag.

(staticFS fs.FS)

Source from the content-addressed store, hash-verified

197
198// buildIndexHTML reads index.html and injects the initial config as a script tag.
199func (s *Server) buildIndexHTML(staticFS fs.FS) []byte {
200 raw, err := fs.ReadFile(staticFS, "index.html")
201 if err != nil {
202 return []byte("<!-- failed to read index.html -->")
203 }
204
205 phases := s.config.Phases
206 if phases == nil {
207 phases = []PhaseInfo{}
208 }
209 cfg := ConfigResponse{
210 ReadOnly: s.config.ReadOnly,
211 Version: s.config.Version,
212 Phases: phases,
213 }
214 cfgJSON, err := json.Marshal(cfg)
215 if err != nil {
216 return raw
217 }
218
219 // Inject right before </head>
220 script := fmt.Sprintf(`<script>window.__TASKMD_CONFIG__=%s;</script>`, cfgJSON)
221 return bytes.Replace(raw, []byte("</head>"), []byte(script+"</head>"), 1)
222}
223
224func (s *Server) mountFallback(mux *http.ServeMux) {
225 mux.HandleFunc("/{path...}", func(w http.ResponseWriter, r *http.Request) {

Callers 1

mountStaticMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected