From 35687c90084ed61d00b17f1656c5a3db58f67b61 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 24 Sep 2026 20:34:44 -0700 Subject: Add back logging --- roseh.moe.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'roseh.moe.go') diff --git a/roseh.moe.go b/roseh.moe.go index f41d184..637c22b 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -1138,6 +1138,19 @@ func (h *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.h.ServeHTTP(w, r) } +type loggingHandler struct { + h http.Handler +} + +func (h *loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + u := *r.URL + if strings.HasPrefix(u.Path, "/otp/") { + u.Path = "/otp/__REDACTED__" + } + log.Printf("%q from %q", r.Method+" "+r.Host+u.String(), r.RemoteAddr) + h.h.ServeHTTP(w, r) +} + func main() { flag.Parse() @@ -1216,12 +1229,13 @@ func main() { apiMux.HandleFunc("PUT /api/wormhole/{name}", wormholeAPIUpload) mux.Handle("/api/", apiMux) mux.HandleFunc("/", notFound) - http.Handle(selfURL.Hostname()+"/", http.NewCrossOriginProtection().Handler(&gzipHandler{mux})) + serverMux := http.NewServeMux() + serverMux.Handle(selfURL.Hostname()+"/", http.NewCrossOriginProtection().Handler(&gzipHandler{mux})) jellyfinURL, err := url.Parse("http://127.0.0.1:8096") if err != nil { log.Fatal(err) } - http.Handle("cinema."+selfURL.Hostname()+"/", &authHandler{h: &httputil.ReverseProxy{ + serverMux.Handle("cinema."+selfURL.Hostname()+"/", &authHandler{h: &httputil.ReverseProxy{ Rewrite: func(r *httputil.ProxyRequest) { r.SetURL(jellyfinURL) r.SetXForwarded() @@ -1243,7 +1257,8 @@ func main() { } cgitCGI.PathLocationHandler = cgitCGI codeMux.Handle("/", cgitCGI) - http.Handle("code."+selfURL.Hostname()+"/", &gzipHandler{codeMux}) + serverMux.Handle("code."+selfURL.Hostname()+"/", &gzipHandler{codeMux}) + handler := &loggingHandler{serverMux} port := selfURL.Port() if port == "" { @@ -1255,8 +1270,8 @@ func main() { addr := ":" + port log.Printf("Listening on %q", addr) if *https != "" { - log.Fatal(http.ListenAndServeTLS(addr, *https+"/cert.pem", *https+"/key.pem", nil)) + log.Fatal(http.ListenAndServeTLS(addr, *https+"/cert.pem", *https+"/key.pem", handler)) } else { - log.Fatal(http.ListenAndServe(addr, nil)) + log.Fatal(http.ListenAndServe(addr, handler)) } } -- cgit v1.3.1