From d6d039fe26b16ad0007e2aaadc1f6b7457a9d4bf Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 18 Jun 2014 21:57:12 -0700 Subject: [PATCH 1/2] Left pad messages containing colon with space. Fixes #10 --- app.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 64e1053..fa043c0 100644 --- a/app.js +++ b/app.js @@ -31,8 +31,7 @@ app.use(express.cookieParser()); app.use(express.static(__dirname + '/public')); app.use(express.bodyParser()); -// App - +// App routes app.get('/', function(req, res) { fs.readFile(__dirname + '/views/index.html', 'utf8', function(err, text){ res.send(text); @@ -61,6 +60,8 @@ app.post('/intl', function(req, res) { textRequestHandler(req, res, stripPhone(req.body.number), 'intl', req.query.key); }); +// App helper functions + function textRequestHandler(req, res, number, region, key) { if (!req.body.number || !req.body.message) { mpq.track('incomplete request'); @@ -71,9 +72,9 @@ function textRequestHandler(req, res, number, region, key) { mpq.track('textRequestHandler entry', {number: req.body.number, message: req.body.message, ip: ip, region: region}); var message = req.body.message; - if (message.indexOf('http') === 0) { + if (message.indexOf(':') > -1) { // Handle problem with vtext where message would not get sent properly if it - // begins with h ttp + // contains a colon message = ' ' + message; } @@ -206,6 +207,7 @@ function sendText(phone, message, region, cb) { }); } +// Start server var port = process.env.PORT || 9090; app.listen(port, function() { console.log('Listening on', port); From 991217efad28baa9aace9f4f6aeb1f95a0f7a089 Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Fri, 27 Jun 2014 23:44:19 -0700 Subject: [PATCH 2/2] add remoteAddress fallback --- app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 2ea5ea3..db81ad9 100644 --- a/app.js +++ b/app.js @@ -46,7 +46,7 @@ app.get('/providers/:region', function(req, res) { app.post('/text', function(req, res) { var number = stripPhone(req.body.number); if (number.length < 9 || number.length > 10) { - res.send({success:false,message:'Invalid phone number.'}); + res.send({success:false, message:'Invalid phone number.'}); return; } textRequestHandler(req, res, number, 'us', req.query.key); @@ -65,10 +65,10 @@ app.post('/intl', function(req, res) { function textRequestHandler(req, res, number, region, key) { if (!req.body.number || !req.body.message) { mpq.track('incomplete request'); - res.send({success:false,message:'Number and message parameters are required.'}); + res.send({success:false, message:'Number and message parameters are required.'}); return; } - var ip = req.header('X-Real-IP');// || req.connection.remoteAddress; + var ip = req.header('X-Real-IP') || req.connection.remoteAddress; var message = req.body.message; if (message.indexOf(':') > -1) {