Skip to content

Commit

Permalink
server: add a healthcheck route at /_internal/healthcheck
Browse files Browse the repository at this point in the history
Closes #904.
  • Loading branch information
fsouza committed Aug 27, 2022
1 parent 8edf84e commit 58265a5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fakestorage/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ func (s *Server) buildMuxer() {
const apiPrefix = "/storage/v1"
s.mux = mux.NewRouter()

// healthcheck
s.mux.Path("/_internal/healthcheck").Methods(http.MethodGet).HandlerFunc(s.healthcheck)

routers := []*mux.Router{
s.mux.PathPrefix(apiPrefix).Subrouter(),
s.mux.MatcherFunc(s.publicHostMatcher).PathPrefix(apiPrefix).Subrouter(),
Expand Down Expand Up @@ -268,6 +271,10 @@ func (s *Server) buildMuxer() {
s.mux.Host("{bucketName:.+}").Path("/{objectName:.+}").Methods(http.MethodPost, http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.insertObject))
}

func (s *Server) healthcheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

// publicHostMatcher matches incoming requests against the currently specified server publicHost.
func (s *Server) publicHostMatcher(r *http.Request, rm *mux.RouteMatch) bool {
if strings.Contains(s.publicHost, ":") || !strings.Contains(r.Host, ":") {
Expand Down

0 comments on commit 58265a5

Please sign in to comment.