hako/webapp/embed.go
Felipe M. 4fcf97c9fd
Some checks failed
CI / goreleaser-lint (pull_request) Successful in 15s
CI / format (pull_request) Successful in 2m19s
CI / lint (pull_request) Successful in 3m53s
CI / test (pull_request) Failing after 3m26s
CI / e2e (pull_request) Failing after 1m39s
CI / build (pull_request) Successful in 3m59s
fix: use all:dist embed directive to include dot-files
2026-04-07 18:26:06 +02:00

30 lines
772 B
Go

package webapp
import (
"embed"
"io/fs"
"net/http"
"os"
)
//go:embed all:dist
var embeddedWebappFS embed.FS
// GetFilesystem returns a HTTP filesystem with the embedded webapp files
func GetFilesystem() (http.FileSystem, error) {
// Try embedded filesystem first (production mode)
if embeddedFS, err := fs.Sub(embeddedWebappFS, "dist"); err == nil {
// Check if embedded filesystem has content by trying to open index.html
if _, err := embeddedFS.Open("index.html"); err == nil {
return http.FS(embeddedFS), nil
}
}
// Fallback to filesystem for development (when dist exists locally)
if _, err := os.Stat("dist"); err == nil {
return http.Dir("dist"), nil
}
// Fall back to an empty filesystem if files don't exist
return http.Dir("."), nil
}