Files
skillshare/internal/server/embed.go
T
Willie d30d90af76 feat: update Homebrew install to homebrew-core and detect missing UI
- Update Homebrew command from tap (runkids/tap/skillshare) to
  homebrew-core (brew install skillshare) in README, website homepage,
  and getting-started docs
- Add note that Homebrew build is CLI-only (no web dashboard)
- Add IsUIBuilt() detection in embed.go/embed_dev.go to check for
  placeholder UI at startup
- Show CLI warning with install instructions when skillshare ui is
  run on a build without the frontend
- Add Homebrew Note section to commands/ui.md with migration steps
2026-02-15 16:18:26 +08:00

61 lines
1.4 KiB
Go

//go:build !dev
package server
import (
"embed"
"io/fs"
"net/http"
"os"
"strings"
)
// IsUIBuilt reports whether the embedded dist contains a real frontend build.
// Returns false when the dist only contains a placeholder (e.g. Homebrew or make build without UI).
func IsUIBuilt() bool {
data, err := distFS.ReadFile("dist/index.html")
if err != nil {
return false
}
return !strings.Contains(string(data), "UI not built")
}
//go:embed all:dist
var distFS embed.FS
// spaHandler returns a handler that serves the embedded SPA.
// Unknown paths fall back to index.html for client-side routing.
func spaHandler() http.Handler {
sub, err := fs.Sub(distFS, "dist")
if err != nil {
panic("embed: " + err.Error())
}
fileServer := http.FileServer(http.FS(sub))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Try to serve the file directly
path := strings.TrimPrefix(r.URL.Path, "/")
if path == "" {
path = "index.html"
}
if _, err := fs.Stat(sub, path); err == nil {
fileServer.ServeHTTP(w, r)
return
}
// SPA fallback: serve index.html for unknown paths
index, err := fs.ReadFile(sub, "index.html")
if err != nil {
if os.IsNotExist(err) {
http.Error(w, "UI not built. Run: make ui-build", http.StatusNotFound)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(index)
})
}