2023-05-28 00:54:04 +00:00
|
|
|
package beacon
|
|
|
|
|
|
|
|
import (
|
2023-11-15 14:07:16 +00:00
|
|
|
"fmt"
|
2023-06-08 07:43:27 +00:00
|
|
|
"net"
|
2023-05-28 00:54:04 +00:00
|
|
|
"net/http"
|
|
|
|
|
2023-11-15 14:07:16 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/beacon/beacon_router_configuration"
|
2023-06-08 07:43:27 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/beacon/handler"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
2023-05-28 00:54:04 +00:00
|
|
|
)
|
|
|
|
|
2023-11-15 14:07:16 +00:00
|
|
|
func ListenAndServe(api *handler.ApiHandler, routerCfg beacon_router_configuration.RouterConfiguration) {
|
2023-06-08 07:43:27 +00:00
|
|
|
listener, err := net.Listen(routerCfg.Protocol, routerCfg.Address)
|
2023-11-15 14:07:16 +00:00
|
|
|
fmt.Println(routerCfg.Address, routerCfg.Protocol)
|
2023-06-08 07:43:27 +00:00
|
|
|
server := &http.Server{
|
2023-08-30 23:18:12 +00:00
|
|
|
Handler: newBeaconMiddleware(api),
|
2023-06-08 07:43:27 +00:00
|
|
|
ReadTimeout: routerCfg.ReadTimeTimeout,
|
|
|
|
IdleTimeout: routerCfg.IdleTimeout,
|
|
|
|
WriteTimeout: routerCfg.IdleTimeout,
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("[Beacon API] Failed to start listening", "addr", routerCfg.Address, "err", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := server.Serve(listener); err != nil {
|
|
|
|
log.Warn("[Beacon API] failed to start serving", "addr", routerCfg.Address, "err", err)
|
|
|
|
}
|
2023-05-28 00:54:04 +00:00
|
|
|
}
|