- Updated branding from "SolaceScanScout" to "Solace" across various files including deployment scripts, API responses, and documentation. - Changed default base URL for Playwright tests and updated security headers to reflect the new branding. - Enhanced README and API documentation to include new authentication endpoints and product access details. This refactor aligns the project branding and improves clarity in the API documentation.
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package track1
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// HandleMissionControlStream sends periodic text/event-stream payloads with full bridge/status data (for SPA or tooling).
|
|
func (s *Server) HandleMissionControlStream(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeError(w, http.StatusMethodNotAllowed, "method_not_allowed", "Method not allowed")
|
|
return
|
|
}
|
|
|
|
controller := http.NewResponseController(w)
|
|
|
|
w.Header().Set("Content-Type", "text/event-stream")
|
|
w.Header().Set("Cache-Control", "no-cache")
|
|
w.Header().Set("Connection", "keep-alive")
|
|
w.Header().Set("X-Accel-Buffering", "no")
|
|
|
|
// Immediate event so nginx unbuffers and short curl probes see `event:`/`data:` before RPC probes finish.
|
|
_, _ = fmt.Fprintf(w, ": mission-control stream\n\nevent: ping\ndata: {}\n\n")
|
|
_ = controller.Flush()
|
|
|
|
tick := time.NewTicker(20 * time.Second)
|
|
defer tick.Stop()
|
|
|
|
send := func() bool {
|
|
ctx, cancel := context.WithTimeout(r.Context(), 12*time.Second)
|
|
defer cancel()
|
|
data := s.BuildBridgeStatusData(ctx)
|
|
payload, err := json.Marshal(map[string]interface{}{"data": data})
|
|
if err != nil {
|
|
return false
|
|
}
|
|
_, _ = fmt.Fprintf(w, "event: mission-control\ndata: %s\n\n", payload)
|
|
return controller.Flush() == nil
|
|
}
|
|
|
|
if !send() {
|
|
return
|
|
}
|
|
|
|
for {
|
|
select {
|
|
case <-r.Context().Done():
|
|
return
|
|
case <-tick.C:
|
|
if !send() {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|