From bc087b8cc28aa721b12050e04c2ad1c7629b0bb0 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Wed, 13 Nov 2013 08:48:52 -0800 Subject: [PATCH] Rate limit by real ip --- app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 86df7aa..181b887 100644 --- a/app.js +++ b/app.js @@ -40,8 +40,9 @@ app.post('/text', function(req, res) { return; } + var ip = req.headers['X-Real-IP'] || req.connection.remoteAddress; mpq.track('text', - {number: req.body.number, message: req.body.message, ip: req.connection.remoteAddress}); + {number: req.body.number, message: req.body.message, ip: ip}); var number = stripPhone(req.body.number); if (number.length < 9 || number.length > 10) { @@ -49,7 +50,7 @@ app.post('/text', function(req, res) { return; } - var ipkey = 'textbelt:ip:' + req.connection.remoteAddress + '_' + dateStr(); + var ipkey = 'textbelt:ip:' + ip + '_' + dateStr(); var phonekey = 'textbelt:phone:' + number; redis.incr(phonekey, function(err, num) {