42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
// Command webui is a tiny static file server for the StreamHub browser SPA.
|
|
//
|
|
// It serves the existing Client/udpstreamer/static directory; the SPA talks
|
|
// WebSocket directly to the C++ StreamHub (pass ?hub=host:8090 in the URL).
|
|
//
|
|
// Usage:
|
|
//
|
|
// webui -addr :8080 -static ../udpstreamer/static
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
var buildVersion = "streamhub-webui-dev"
|
|
|
|
func main() {
|
|
addr := flag.String("addr", ":8080", "HTTP listen address")
|
|
static := flag.String("static", "../udpstreamer/static", "directory with the SPA files")
|
|
hub := flag.String("hub", "localhost:8090", "StreamHub WebSocket host:port the SPA should connect to")
|
|
flag.Parse()
|
|
|
|
http.Handle("/", http.FileServer(http.Dir(*static)))
|
|
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprint(w, buildVersion)
|
|
})
|
|
// The SPA fetches /hub at startup to discover the StreamHub address, so
|
|
// plain http://localhost:8080/ works without a ?hub= query parameter.
|
|
http.HandleFunc("/hub", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprint(w, *hub)
|
|
})
|
|
|
|
log.Printf("StreamHub WebUI listening on %s (static=%s, hub=%s)", *addr, *static, *hub)
|
|
log.Printf("open http://localhost%s/", *addr)
|
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
|
log.Fatalf("http: %v", err)
|
|
}
|
|
}
|