From 14887722a0b9bfb37bc9ee9cfe0ef773e2eb2369 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 12 Dec 2025 22:17:40 +0000 Subject: [PATCH] Add debug endpoints for SMS POST webhook This gets me data in the log, which actually has content. --- endpoint.go | 31 +++++++++++++++++++++++++++++++ main.go | 2 ++ 2 files changed, 33 insertions(+) diff --git a/endpoint.go b/endpoint.go index 397632ba..958ba543 100644 --- a/endpoint.go +++ b/endpoint.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "io" "net/http" "strconv" "strings" @@ -178,6 +179,36 @@ func getSource(w http.ResponseWriter, r *http.Request, u *models.User) { htmlSource(w, r, u, globalid) } +func postSMS(w http.ResponseWriter, r *http.Request) { + // Log all request headers + log.Info().Msg("===== REQUEST HEADERS =====") + for name, values := range r.Header { + for _, value := range values { + log.Info().Str("name", name).Str("value", value).Msg("header") + } + } + + // Read and log the request body + bodyBytes, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, "Failed to read request body", http.StatusInternalServerError) + return + } + + // Close the original body + r.Body.Close() + + // Create a new body for further processing if needed + //r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + + // Log the body + log.Info().Str("body", string(bodyBytes)).Msg("got body") + + // Respond with "ok" + w.Header().Set("Content-Type", "text/plain") + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) +} func getSMS(w http.ResponseWriter, r *http.Request) { org := chi.URLParam(r, "org") diff --git a/main.go b/main.go index f6d1c0e0..55a3ad7d 100644 --- a/main.go +++ b/main.go @@ -132,8 +132,10 @@ func main() { r.Get("/signup", getSignup) r.Post("/signup", postSignup) r.Get("/sms", getSMS) + r.Post("/sms", postSMS) r.Get("/sms.php", getSMS) r.Get("/sms/{org}", getSMS) + r.Post("/sms/{org}", postSMS) // Authenticated endpoints r.Method("GET", "/cell/{cell}", NewEnsureAuth(getCellDetails))