From 3a5d8835bed223cba85dae82dcecd63ca38d14db Mon Sep 17 00:00:00 2001 From: Mikhail Swift Date: Thu, 6 Jun 2024 15:45:56 -0400 Subject: [PATCH] fix: add readiness handler, only accept POST on webhook handlers --- main.go | 6 ++++++ server/server.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e386869..943b8d6 100644 --- a/main.go +++ b/main.go @@ -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, @@ -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) +} diff --git a/server/server.go b/server/server.go index 9c1cf26..4f31ccf 100644 --- a/server/server.go +++ b/server/server.go @@ -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