From 30b736d864e087caf40993e9d278d5cc3157ab86 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Apr 2026 15:12:53 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E3=83=AA=E3=82=AF=E3=82=A8?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=AD=E3=82=B0=E3=81=A8=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=88=E8=A8=AD=E5=AE=9A=E3=81=AE=E7=92=B0=E5=A2=83=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E5=AF=BE=E5=BF=9C=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://claude.ai/code/session_01F3cPFEgKvjkca2LAyWsjj2 --- main.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 959b4b2..073f56a 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,32 @@ package main import ( - "fmt" "log" "net/http" + "os" ) +// loggingMiddleware logs each incoming HTTP request. +func loggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + log.Printf("request: %s %s %s", r.Method, r.URL.Path, r.RemoteAddr) + next.ServeHTTP(w, r) + }) +} + func main() { store := NewStore() mux := http.NewServeMux() registerRoutes(mux, store) - addr := ":8080" - fmt.Println("BringIt server started on http://localhost" + addr) - log.Fatal(http.ListenAndServe(addr, mux)) + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + addr := ":" + port + + handler := loggingMiddleware(mux) + + log.Printf("BringIt server starting on %s", addr) + log.Fatal(http.ListenAndServe(addr, handler)) } From c2482c0b30bbb788bfdc0ce9fc53755793a2b951 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Apr 2026 15:13:54 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=83=AC=E3=83=B3=E3=83=80=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://claude.ai/code/session_01F3cPFEgKvjkca2LAyWsjj2 --- handler.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/handler.go b/handler.go index c771bb9..e8385ce 100644 --- a/handler.go +++ b/handler.go @@ -2,6 +2,7 @@ package main import ( "html/template" + "log" "net/http" "strings" ) @@ -37,7 +38,10 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - tmpl.ExecuteTemplate(w, "index.html", nil) + if err := tmpl.ExecuteTemplate(w, "index.html", nil); err != nil { + log.Printf("error rendering index template: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } } func handleCreateList(store *Store) http.HandlerFunc { @@ -49,6 +53,7 @@ func handleCreateList(store *Store) http.HandlerFunc { } desc := strings.TrimSpace(r.FormValue("description")) l := store.CreateList(title, desc) + log.Printf("list created: token=%s title=%q", l.ShareToken, title) http.Redirect(w, r, "/lists/"+l.ShareToken, http.StatusSeeOther) } } @@ -65,13 +70,20 @@ func handleShowList(store *Store) http.HandlerFunc { "List": l, "ShareURL": "http://" + r.Host + "/lists/" + l.ShareToken, } - tmpl.ExecuteTemplate(w, "list.html", data) + if err := tmpl.ExecuteTemplate(w, "list.html", data); err != nil { + log.Printf("error rendering list template: token=%s err=%v", token, err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } } } func handleAddItem(store *Store) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { token := r.PathValue("token") + if store.GetList(token) == nil { + http.NotFound(w, r) + return + } name := strings.TrimSpace(r.FormValue("name")) if name == "" { http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) @@ -80,6 +92,7 @@ func handleAddItem(store *Store) http.HandlerFunc { assignee := strings.TrimSpace(r.FormValue("assignee")) required := r.FormValue("required") == "on" store.AddItem(token, name, assignee, required) + log.Printf("item added: token=%s name=%q assignee=%q", token, name, assignee) http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) } } @@ -89,6 +102,7 @@ func handleTogglePrepared(store *Store) http.HandlerFunc { token := r.PathValue("token") id := r.PathValue("id") store.TogglePrepared(token, id) + log.Printf("item toggle-prepared: token=%s id=%s", token, id) http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) } } @@ -98,6 +112,7 @@ func handleToggleRequired(store *Store) http.HandlerFunc { token := r.PathValue("token") id := r.PathValue("id") store.ToggleRequired(token, id) + log.Printf("item toggle-required: token=%s id=%s", token, id) http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) } } @@ -108,6 +123,7 @@ func handleUpdateAssignee(store *Store) http.HandlerFunc { id := r.PathValue("id") assignee := strings.TrimSpace(r.FormValue("assignee")) store.UpdateAssignee(token, id, assignee) + log.Printf("item assignee updated: token=%s id=%s assignee=%q", token, id, assignee) http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) } } @@ -117,6 +133,7 @@ func handleDeleteItem(store *Store) http.HandlerFunc { token := r.PathValue("token") id := r.PathValue("id") store.DeleteItem(token, id) + log.Printf("item deleted: token=%s id=%s", token, id) http.Redirect(w, r, "/lists/"+token, http.StatusSeeOther) } } From fe2ffa54238b8538e034378ca33068573cd45c28 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 3 Apr 2026 15:14:11 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E3=82=B7=E3=82=A7=E3=82=A2URL?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=AD=E3=83=88=E3=82=B3=E3=83=AB=E6=A4=9C?= =?UTF-8?q?=E5=87=BA=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://claude.ai/code/session_01F3cPFEgKvjkca2LAyWsjj2 --- handler.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index e8385ce..74ebb33 100644 --- a/handler.go +++ b/handler.go @@ -58,6 +58,16 @@ func handleCreateList(store *Store) http.HandlerFunc { } } +func detectScheme(r *http.Request) string { + if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { + return proto + } + if r.TLS != nil { + return "https" + } + return "http" +} + func handleShowList(store *Store) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { token := r.PathValue("token") @@ -66,9 +76,10 @@ func handleShowList(store *Store) http.HandlerFunc { http.NotFound(w, r) return } + scheme := detectScheme(r) data := map[string]any{ "List": l, - "ShareURL": "http://" + r.Host + "/lists/" + l.ShareToken, + "ShareURL": scheme + "://" + r.Host + "/lists/" + l.ShareToken, } if err := tmpl.ExecuteTemplate(w, "list.html", data); err != nil { log.Printf("error rendering list template: token=%s err=%v", token, err)