diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2026-09-24 20:34:44 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2026-09-24 20:34:44 -0700 |
| commit | 35687c90084ed61d00b17f1656c5a3db58f67b61 (patch) | |
| tree | 788732a52b1ec09b0b0e23a21e096f9dd8321bbd /roseh.moe.go | |
| parent | Clean up logging and error handling (diff) | |
| download | roseh.moe-35687c90084ed61d00b17f1656c5a3db58f67b61.tar.zst | |
Add back logging
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 25 |
1 files changed, 20 insertions, 5 deletions
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)) } } |
