Skip to content

Commit

Permalink
Fix user count IP using proxy IP
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-ceccato committed Feb 8, 2024
1 parent 852602a commit 98b09e0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const ipAddresses = {};

// Function to track IP addresses and timestamps
const trackIP = (ip) => {
const ip = (req.headers['x-forwarded-for'] || '').split(',').pop().trim() ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
ipAddresses[ip] = Date.now();
};

Expand Down Expand Up @@ -122,10 +126,6 @@ getPomoStateJSON = () => {
app.get("/json-endpoint", cors(), (req, res) => {
const ip = req.ip || req.connection.remoteAddress; // Get IP address
trackIP(ip); // Track IP
//console.log(
//"Received request from: " + req.ip + " at " + new Date().toISOString()
//);
//console.log(getPomoStateJSON());
res.json(getPomoStateJSON());
});

Expand Down

0 comments on commit 98b09e0

Please sign in to comment.