erigon-pulse/diagnostics/nodeinfo.go
Mark Holt f794438335
Diag session routing (#8232)
Code to support react based UI for diagnostics:

* pprof, prometheus and diagnistics rationalized to use a single router
(i.e. they can all run in the same port)
* support_cmd updated to support node routing (was only first node)
* Multi content support in router tunnel (application/octet-stream &
appliaction/json)
* Routing requests changed from using http forms to rest + query params
* REST query requests can now be made against erigon base port and
diagnostics with the same url format/params

---------

Co-authored-by: dvovk <vovk.dimon@gmail.com>
Co-authored-by: Mark Holt <mark@disributed.vision>
2023-09-25 16:24:17 +01:00

27 lines
590 B
Go

package diagnostics
import (
"encoding/json"
"net/http"
"github.com/ledgerwatch/erigon/turbo/node"
)
func SetupNodeInfoAccess(metricsMux *http.ServeMux, node *node.ErigonNode) {
metricsMux.HandleFunc("/nodeinfo", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
writeNodeInfo(w, node)
})
}
func writeNodeInfo(w http.ResponseWriter, node *node.ErigonNode) {
reply, err := node.Backend().NodesInfo(0)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(reply)
}