Skip to content

Commit

Permalink
feat(api): add x-beaconchain-version header to all responses
Browse files Browse the repository at this point in the history
  • Loading branch information
guybrush committed Nov 20, 2024
1 parent 308e4a3 commit 2167f00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func Run() {
dummy := dataaccess.NewDummyService()

router := api.NewApiRouter(dataAccessor, dummy, cfg)
router.Use(version.HttpMiddleware)
router.Use(api.GetCorsMiddleware(cfg.CorsAllowedHosts))

if utils.Config.Metrics.Enabled {
Expand Down
7 changes: 7 additions & 0 deletions backend/pkg/commons/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package version

import (
"net/http"
"runtime"
)

Expand All @@ -12,3 +13,9 @@ var (
BuildDate = "undefined"
GoVersion = runtime.Version()
)

func HttpMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Header.Set("X-Beaconchain-Version", Version)
})
}

0 comments on commit 2167f00

Please sign in to comment.