Include config in status response and push on SIGHUP
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
16
http.go
16
http.go
@@ -25,6 +25,7 @@ const (
|
||||
)
|
||||
|
||||
type StatusResponse struct {
|
||||
Config *Config `json:"config"`
|
||||
Nodes []*Node `json:"nodes"`
|
||||
Links []*Link `json:"links"`
|
||||
MulticastGroups []*MulticastGroupMembers `json:"multicast_groups"`
|
||||
@@ -45,7 +46,6 @@ func (t *Tendrils) startHTTPServer() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/api/status", t.handleAPIStatus)
|
||||
mux.HandleFunc("/api/status/stream", t.handleAPIStatusStream)
|
||||
mux.HandleFunc("/api/config", t.handleAPIConfig)
|
||||
mux.HandleFunc("/api/errors/clear", t.handleClearError)
|
||||
mux.Handle("/", http.FileServer(http.Dir("static")))
|
||||
|
||||
@@ -124,22 +124,18 @@ func (t *Tendrils) handleAPIStatus(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(status)
|
||||
}
|
||||
|
||||
func (t *Tendrils) handleAPIConfig(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if t.config == nil {
|
||||
json.NewEncoder(w).Encode(&Config{})
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(t.config)
|
||||
}
|
||||
|
||||
func (t *Tendrils) GetStatus() *StatusResponse {
|
||||
var broadcastStats *BroadcastStatsResponse
|
||||
if t.broadcast != nil {
|
||||
stats := t.broadcast.GetStats()
|
||||
broadcastStats = &stats
|
||||
}
|
||||
config := t.config
|
||||
if config == nil {
|
||||
config = &Config{}
|
||||
}
|
||||
return &StatusResponse{
|
||||
Config: config,
|
||||
Nodes: t.getNodes(),
|
||||
Links: t.getLinks(),
|
||||
MulticastGroups: t.getMulticastGroups(),
|
||||
|
||||
@@ -1725,13 +1725,10 @@
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
evtSource.addEventListener('status', async (event) => {
|
||||
evtSource.addEventListener('status', (event) => {
|
||||
resetHeartbeat();
|
||||
const data = JSON.parse(event.data);
|
||||
if (!currentConfig) {
|
||||
const configResp = await fetch('/api/config');
|
||||
currentConfig = await configResp.json();
|
||||
}
|
||||
currentConfig = data.config || {};
|
||||
render(data, currentConfig);
|
||||
});
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ func (t *Tendrils) Run() {
|
||||
}
|
||||
t.config = cfg
|
||||
log.Printf("reloaded config from %s", t.ConfigFile)
|
||||
t.NotifyUpdate()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user