From bcc967f7d7af98b0886fb99c7c79656bb69571d9 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Wed, 13 May 2026 15:20:17 +0200 Subject: [PATCH] feat(main): add request logging and configurable server address Add logging to `sendHandler` and `sendParamsHandler` to track incoming requests. Update the server startup logic to use `HOST` and `PORT` environment variables, defaulting to `localhost:660` if not provided. --- main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 3870d16..de3614e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "html" "log" "net/http" + "os" "strconv" "strings" @@ -208,6 +209,7 @@ var domainMap = map[string]EmailConfig{ } func sendHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("[send] INCOMING %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr) if r.Method != http.MethodPost { http.Error(w, "POST only", http.StatusMethodNotAllowed) return @@ -301,6 +303,7 @@ func enableCors(handler http.HandlerFunc) http.HandlerFunc { // // GET /send-params?email=user@example.com&pass=secret&server=smtp.example.com&port=465&to=dest@example.com&from=user@example.com&subject=Hello&message=Hi func sendParamsHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("[send-params] INCOMING %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr) if r.Method != http.MethodGet { http.Error(w, "GET only", http.StatusMethodNotAllowed) return @@ -363,6 +366,16 @@ func main() { http.HandleFunc("/", enableCors(rootHandler)) http.HandleFunc("/send", enableCors(sendHandler)) http.HandleFunc("/send-params", enableCors(sendParamsHandler)) - log.Println("Server running on localhost:660") - log.Fatal(http.ListenAndServe("localhost:660", nil)) + + host := os.Getenv("HOST") + if host == "" { + host = "localhost" + } + port := os.Getenv("PORT") + if port == "" { + port = "660" + } + addr := host + ":" + port + log.Println("Server running on " + addr) + log.Fatal(http.ListenAndServe(addr, nil)) }