0

My app's Ionic 2 powered front-end POSTes some user data to the app's NodeJS / ExpressJS powered backend.

All I want to do is to use Twilio Authy's register_user() method inside the success callback function of ExpressJS's app.post().

Front-end POSTes to URL:

https://my-bluemix-app-placeholder/forTwilio

But everytime its throwing 500 Internal server error.

But I have checked and rechecked for any misconfig and found nothing.

In the follwing code I've used direct input values. I am sharing my code below.

var loopback = require('loopback');
var boot = require('loopback-boot');
var helmet = require('helmet');
var errorHandler = require('strong-error-handler');
var bodyParser = require('body-parser');

var imf = require('bms-mca-oauth-sdk');

// Twilio Authy
var authy = require('authy')['DxJRXLSj6Tl4jD7ytHLx0bhXLEnonbOc'];

var app = module.exports = loopback();
app.use(helmet());
app.use(errorHandler({debug:true, log:true}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

var authyUsrId = "";
app.post('/forTwilio', function(req, res){
    // send the received data to Twilio Authy
    authy.register_user('something@example.com', '7407098203', '91', function(err, res){
        authyUsrId = res.user.id;
    });
    res.send(authyUsrId);
});


// ------------ Protecting backend APIs with Mobile Client Access end -----------------

app.start = function () {
    // start the web server
    return app.listen(function () {
        app.emit('started');
        var baseUrl = app.get('url').replace(/\/$/, '');
        console.log('Web server listening at: %s', baseUrl);
        var componentExplorer = app.get('loopback-component-explorer');
        if (componentExplorer) {
            console.log('Browse your REST API at %s%s', baseUrl, componentExplorer.mountPath);
        }
    });
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function (err) {
    if (err) throw err;
    if (require.main === module)
        app.start();
});
somnathbm
  • 649
  • 1
  • 9
  • 19

1 Answers1

1

Silly mistake. The problem is in the line.

// Twilio Authy
var authy = require('authy')['DxJRXLSj6Tl4jD7ytHLx0bhXLEnonbOc'];

It should be

// Twilio Authy
var authy = require('authy')('DxJRXLSj6Tl4jD7ytHLx0bhXLEnonbOc');
somnathbm
  • 649
  • 1
  • 9
  • 19