(embeddedFS fs.FS)
| 550 | } |
| 551 | |
| 552 | func (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 | |
| 587 | func (h *httpHandlers) handleManifest(manifestFileBytes []byte) http.HandlerFunc { |
| 588 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected