8e08c73f60
Full-stack Go monolith with embedded React frontend for orchestrating rsync-over-SSH file synchronization with Wake-on-LAN support. Features: - JWT auth (HS256) with bcrypt password hashing - CRUD for machines (with WoL config) and sync_pairs - Ed25519 SSH key generation and known_hosts management - WoL magic packet sender + TCP-connect waiter with backoff - Sync engine: rsync subprocess, per-pair job queue, progress parsing - Homebrew cron parser for scheduled syncs - SSE stream for live job status (queued/waking_up/running/success/failed) - React+TS+Vite+Tailwind SPA embedded via embed.FS - Debian packaging with systemd unit, postinst/prerm/postrm Tech stack: - Go 1.22+ (CGO_ENABLED=0, pure SQLite via modernc.org/sqlite) - chi router for HTTP API - TypeScript + React 18 + Tailwind CSS frontend - Cross-compiled to Linux amd64 for Proxmox LXC deployment Tests: wol (MAC parsing, magic packet), syncengine/queue, scheduler/cron
44 lines
930 B
Go
44 lines
930 B
Go
package webui
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
)
|
|
|
|
//go:embed dist
|
|
var DistFS embed.FS
|
|
|
|
var Dist fs.FS = DistFS
|
|
|
|
func ServeHTTP() http.Handler {
|
|
return http.FileServer(http.FS(DistFS))
|
|
}
|
|
|
|
func ServeSPA() http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
path := r.URL.Path
|
|
if path == "/" || !isStaticAsset(path) {
|
|
data, err := DistFS.ReadFile("dist/index.html")
|
|
if err != nil {
|
|
http.Error(w, "not found", http.StatusNotFound)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "text/html")
|
|
w.Write(data)
|
|
return
|
|
}
|
|
http.FileServer(http.FS(DistFS)).ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func isStaticAsset(path string) bool {
|
|
exts := []string{".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".eot", ".map"}
|
|
for _, ext := range exts {
|
|
if len(path) > len(ext) && path[len(path)-len(ext):] == ext {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|