mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
27 lines
590 B
Go
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)
|
||
|
}
|