MCPcopy
hub / github.com/wavetermdev/waveterm / handleStaticFiles

Method handleStaticFiles

tsunami/engine/serverhandlers.go:552–585  ·  view source on GitHub ↗
(embeddedFS fs.FS)

Source from the content-addressed store, hash-verified

550}
551
552func (h *httpHandlers) handleStaticFiles(embeddedFS fs.FS) http.HandlerFunc {
553 fileServer := http.FileServer(http.FS(embeddedFS))
554
555 return func(w http.ResponseWriter, r *http.Request) {
556 defer func() {
557 panicErr := util.PanicHandler("handleStaticFiles", recover())
558 if panicErr != nil {
559 http.Error(w, fmt.Sprintf("internal server error: %v", panicErr), http.StatusInternalServerError)
560 }
561 }()
562
563 // Skip if this is an API, files, or static request (already handled by other handlers)
564 if strings.HasPrefix(r.URL.Path, "/api/") || strings.HasPrefix(r.URL.Path, "/files/") || strings.HasPrefix(r.URL.Path, "/static/") {
565 http.NotFound(w, r)
566 return
567 }
568
569 // Handle any path ending with "/" to avoid redirect loops
570 if serveFileDirectly(w, r, embeddedFS, r.URL.Path, "index.html") {
571 return
572 }
573
574 // For other files, check if they exist before serving
575 filePath := strings.TrimPrefix(r.URL.Path, "/")
576 _, err := embeddedFS.Open(filePath)
577 if err != nil {
578 http.NotFound(w, r)
579 return
580 }
581
582 // Serve the file using the file server
583 fileServer.ServeHTTP(w, r)
584 }
585}
586
587func (h *httpHandlers) handleManifest(manifestFileBytes []byte) http.HandlerFunc {
588 return func(w http.ResponseWriter, r *http.Request) {

Callers 1

registerHandlersMethod · 0.95

Calls 4

PanicHandlerFunction · 0.92
serveFileDirectlyFunction · 0.85
OpenMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected