Skip to content

Commit

Permalink
feat(event-receiver): add user ip
Browse files Browse the repository at this point in the history
Add the user's ip to event data, enabling detection of false positives during
geoblocking.

- add ip to each event
  • Loading branch information
amtins committed Nov 7, 2024
1 parent 071da62 commit 12bafbd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion api/handler/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,24 @@ func EventReceiver(w http.ResponseWriter, r *http.Request) {

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

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

// Add user ip
data["user_ip"] = ip

broadcastData, err := json.Marshal(data)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// Forward the JSON payload to connected clients
sse.Broadcast(string(body))
sse.Broadcast(string(broadcastData))
}

// EventDispatcher enables clients to listen for events via Server-Sent Events.
Expand Down

0 comments on commit 12bafbd

Please sign in to comment.