Skip to content

Commit

Permalink
feat: add public url to status api
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Aug 30, 2022
1 parent 72c1bdb commit 5a22b97
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ checkpointz:
states:
max_items: 5
historical_epoch_count: 20

# set public url where checkpointz will be served from
# public_url: https://www.domain.com

beacon:
upstreams:
- name: remote
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ type Handler struct {

eth *eth.Handler
checkpointz *checkpointz.Handler
publicURL string

metrics Metrics
}

func NewHandler(log logrus.FieldLogger, beac beacon.FinalityProvider) *Handler {
func NewHandler(log logrus.FieldLogger, beac beacon.FinalityProvider, publicURL string) *Handler {
return &Handler{
log: log.WithField("module", "api"),

eth: eth.NewHandler(log, beac, "checkpointz"),
checkpointz: checkpointz.NewHandler(log, beac),
publicURL: publicURL,

metrics: NewMetrics("http"),
}
Expand Down Expand Up @@ -215,6 +217,8 @@ func (h *Handler) handleCheckpointzStatus(ctx context.Context, r *http.Request,
return NewInternalServerErrorResponse(nil), err
}

status.PublicURL = h.publicURL

return NewSuccessResponse(ContentTypeResolvers{
ContentTypeJSON: func() ([]byte, error) {
return json.Marshal(status)
Expand Down
3 changes: 3 additions & 0 deletions pkg/beacon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Config struct {

// HistoricalEpochCount determines how many historical epochs the provider will cache.
HistoricalEpochCount int `yaml:"historical_epoch_count"`

// PublicURL is the public URL where checkpointz will be served from
PublicURL string `yaml:"public_url"`
}

// Cache configuration holds configuration for the caches.
Expand Down
2 changes: 1 addition & 1 deletion pkg/checkpointz/checkpointz.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewServer(log *logrus.Logger, conf *Config) *Server {
Cfg: *conf,
log: log,

http: api.NewHandler(log, provider),
http: api.NewHandler(log, provider, conf.Checkpointz.PublicURL),

provider: provider,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/service/checkpointz/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type StatusResponse struct {
Upstreams map[string]*beacon.UpstreamStatus `json:"upstreams"`
Finality *v1.Finality `json:"finality"`
PublicURL string `json:"public_url,omitempty"`
}

type BeaconSlot struct {
Expand Down

0 comments on commit 5a22b97

Please sign in to comment.