Skip to content

Commit

Permalink
fix: add readiness handler, only accept POST on webhook handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailswift committed Jun 6, 2024
1 parent 0140549 commit 3a5d883
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func main() {
r := mux.NewRouter()
r.PathPrefix("/debug").Handler(http.DefaultServeMux)
r.PathPrefix("/webhook").Handler(http.StripPrefix("/webhook", s))
r.Path("/ready").HandlerFunc(readyHandler)

srv := &http.Server{
Addr: listenAddr,
Expand All @@ -85,3 +86,8 @@ func main() {
srv.Shutdown(ctx)
log.Println("shutting down")
}

// for now this just writes 200 back to show the server is up and listening
func readyHandler(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func New(ctx context.Context, config config.Config) (Server, error) {
return s, fmt.Errorf("could not create handler func for webhook %v: %w", name, err)
}

s.r.HandleFunc(fmt.Sprintf("/%v", name), handlerFunc)
s.r.HandleFunc(fmt.Sprintf("/%v", name), handlerFunc).Methods("POST")
}

return s, nil
Expand Down

0 comments on commit 3a5d883

Please sign in to comment.