2016-11-29 3 views
0

ich einen http Post innerhalb .then() tun wollen. Ich habe es schon in vielen diferent Weise ... nichts funktioniert Ich versuche, einen Benutzer zu erstellen und einen http POST nach der Schöpfung zu tun.http Post innerhalb .then()

'use strict'; 

module.exports = function(app) { 
return function(req, res, next) { 
const body = req.body; 

// Get the user service and `create` a new user 
app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then('I WANT HTTP POST WITH PARAMS HERE') 
// On errors, just call our error middleware 
.catch(next); 

}; 
}; 

Ich möchte in der POST

Antwort

2

E-Mail und Passwort senden Sie ein Versprechen in Versprechen Kette zurückkehren kann. Ich würde promitifizierte Anfrage verwenden, um hier ein PostAsync zu machen.

var Promise = require('bluebird') 
var request = Promise.promisifyAll(require('request')) 

app.service('users').create({ 
     email: body.email, 
     password: body.password 
    }).then(function(createUserResp) { 
     return request.postAsync(/**/) 
    }) 
    }).then(function(resp) { 
     // do sth 
    }) 
    .catch(next); 
0
var RP = require('request-promise') 

app.service('users').create({ 
    email: body.email, 
    password: body.password 
}).then(function() { 
    var opt = { 
     url: 'targetUrl', 
     formData: { 
      email: body.email, 
      password: body.password 
      //, json: true // if result is in json format 
     } 
    } 
    return RP.post(opt) 
}).then(function (postResult) { 

}) 
.catch(next);