mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Single-binary web UI for visual skill management — React 19 + Vite frontend embedded via go:embed, Go net/http REST API backend (30+ endpoints). Includes dashboard, skills browser, targets, sync, collect, search, install, config editor, backup/restore, and git sync pages. Also adds Bitbucket/GitLab URL parsing for install, git operations library, skill version checking, CI frontend build steps, Docker sandbox support, and website docs for the ui command.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
//go:build !dev
|
|
|
|
package server
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
//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)
|
|
})
|
|
}
|