Merge branch 'master' of github.com:typpo/textbelt
Conflicts: app.js
This commit is contained in:
commit
2771da2575
12
app.js
12
app.js
@ -43,8 +43,7 @@ app.use(express.cookieParser());
|
|||||||
app.use(express.static(__dirname + '/public'));
|
app.use(express.static(__dirname + '/public'));
|
||||||
app.use(express.bodyParser());
|
app.use(express.bodyParser());
|
||||||
|
|
||||||
// App
|
// App routes
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
fs.readFile(__dirname + '/views/index.html', 'utf8', function(err, text){
|
fs.readFile(__dirname + '/views/index.html', 'utf8', function(err, text){
|
||||||
res.send(text);
|
res.send(text);
|
||||||
@ -73,6 +72,8 @@ app.post('/intl', function(req, res) {
|
|||||||
textRequestHandler(req, res, stripPhone(req.body.number), 'intl', req.query.key);
|
textRequestHandler(req, res, stripPhone(req.body.number), 'intl', req.query.key);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// App helper functions
|
||||||
|
|
||||||
function textRequestHandler(req, res, number, region, key) {
|
function textRequestHandler(req, res, number, region, key) {
|
||||||
if (!number || !req.body.message) {
|
if (!number || !req.body.message) {
|
||||||
mpq.track('incomplete request');
|
mpq.track('incomplete request');
|
||||||
@ -84,12 +85,12 @@ function textRequestHandler(req, res, number, region, key) {
|
|||||||
res.send({success:false,message:'Sorry, texts to this number are disabled.'});
|
res.send({success:false,message:'Sorry, texts to this number are disabled.'});
|
||||||
return;
|
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;
|
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
|
// Handle problem with vtext where message would not get sent properly if it
|
||||||
// begins with h ttp
|
// contains a colon
|
||||||
message = ' ' + message;
|
message = ' ' + message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +223,7 @@ function sendText(phone, message, region, cb) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start server
|
||||||
var port = process.env.PORT || 9090;
|
var port = process.env.PORT || 9090;
|
||||||
app.listen(port, function() {
|
app.listen(port, function() {
|
||||||
console.log('Listening on', port);
|
console.log('Listening on', port);
|
||||||
|
Loading…
Reference in New Issue
Block a user