MCPcopy
hub / github.com/esm-dev/esm.sh / ServeInternalJS

Method ServeInternalJS

web/handler.go:695–713  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, name string)

Source from the content-addressed store, hash-verified

693}
694
695func (s *Handler) ServeInternalJS(w http.ResponseWriter, r *http.Request, name string) {
696 data, err := efs.ReadFile("internal/" + name + ".js")
697 if err != nil {
698 http.Error(w, "Internal Server Error", 500)
699 return
700 }
701 xx := xxhash.New()
702 xx.Write(data)
703 etag := fmt.Sprintf("w/\"%x\"", xx.Sum(nil))
704 if r.Header.Get("If-None-Match") == etag {
705 w.WriteHeader(http.StatusNotModified)
706 return
707 }
708 header := w.Header()
709 header.Set("Content-Type", "application/javascript; charset=utf-8")
710 header.Set("Cache-Control", "public, max-age=0, must-revalidate")
711 header.Set("Etag", etag)
712 w.Write(data)
713}
714
715func (s *Handler) ServeHmrWS(w http.ResponseWriter, r *http.Request) {
716 if r.Header.Get("Upgrade") != "websocket" {

Callers 1

ServeHTTPMethod · 0.95

Calls 7

ReadFileMethod · 0.80
ErrorMethod · 0.80
WriteMethod · 0.80
WriteHeaderMethod · 0.80
HeaderMethod · 0.80
SetMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected