extra server logging

This commit is contained in:
Erik Winter 2025-01-05 12:56:37 +01:00
parent 788ae0c9ba
commit 83affc6cac
2 changed files with 10 additions and 2 deletions

BIN
dist/plannersync vendored

Binary file not shown.

View File

@ -100,7 +100,7 @@ func (s *Server) SyncGet(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprint(w, string(body))
s.logger.Info("served sync get", "count", len(items), "remoteAddr", r.RemoteAddr)
s.logger.Info("served sync get", "count", len(items), "remoteAddr", getClientIP(r))
}
func (s *Server) SyncPost(w http.ResponseWriter, r *http.Request) {
@ -155,7 +155,7 @@ func (s *Server) SyncPost(w http.ResponseWriter, r *http.Request) {
}
w.WriteHeader(http.StatusNoContent)
s.logger.Info("served sync post", "count", len(items), "remoteAddr", r.RemoteAddr)
s.logger.Info("served sync post", "count", len(items), "remoteAddr", getClientIP(r))
}
// ShiftPath splits off the first component of p, which will be cleaned of
@ -178,3 +178,11 @@ func Index(w http.ResponseWriter, r *http.Request) {
func fmtError(msg string) string {
return fmt.Sprintf(`{"error":%q}`, msg)
}
func getClientIP(r *http.Request) string {
ip := r.Header.Get("X-Real-IP")
if ip == "" {
ip = strings.Split(r.RemoteAddr, ":")[0]
}
return ip
}