Skip to content

Commit

Permalink
feat(event-receiver): handle X-Forwarded-For header
Browse files Browse the repository at this point in the history
Update IP address extraction to prioritize the `X-Forwarded-For` header.

- Fallback to `RemoteAddr` if `X-Forwarded-For` is not present.
  • Loading branch information
amtins committed Nov 14, 2024
1 parent 12bafbd commit 7a34038
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/handler/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func EventReceiver(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Access-Control-Allow-Origin", "*")

ip := r.RemoteAddr
ip := r.Header.Get("X-Forwarded-For")
if ip == "" {
ip = r.RemoteAddr
}

data := map[string]any{}
if err := json.Unmarshal(body, &data); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
Expand Down

0 comments on commit 7a34038

Please sign in to comment.