mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 04:30:04 +00:00
bec91d348e
* use password specific to web UI * fix up a few more tests * tests passing * gaz * fix fmt
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
_ = shared.Service(&Server{})
|
|
log = logrus.WithField("prefix", "prysm-web")
|
|
)
|
|
|
|
// Server for the Prysm Web UI.
|
|
type Server struct {
|
|
http *http.Server
|
|
}
|
|
|
|
// NewServer creates a server service for the Prysm web UI.
|
|
func NewServer(addr string) *Server {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/", webHandler)
|
|
|
|
return &Server{
|
|
http: &http.Server{
|
|
Addr: addr,
|
|
Handler: mux,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Start the web server.
|
|
func (s *Server) Start() {
|
|
go func() {
|
|
log.WithField("address", "http://"+s.http.Addr).Info(
|
|
"Starting Prysm web UI on address, open in browser to access",
|
|
)
|
|
if err := s.http.ListenAndServe(); err != nil {
|
|
log.WithError(err).Error("Failed to run validator web server")
|
|
}
|
|
}()
|
|
}
|
|
|
|
// Stop the web server gracefully with 1s timeout.
|
|
func (s *Server) Stop() error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
|
defer cancel()
|
|
return s.http.Shutdown(ctx)
|
|
}
|
|
|
|
// Status check for web server. Always returns nil.
|
|
func (s *Server) Status() error {
|
|
return nil
|
|
}
|