- Backend REST/gateway/track routes, analytics, Blockscout proxy paths. - Frontend wallet and liquidity surfaces; MetaMask token list alignment. - Deployment docs, verification scripts, address inventory updates. Check: go build ./... under backend/ (pass). Made-with: Cursor
55 lines
1.2 KiB
Go
55 lines
1.2 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")
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|