2016-11-29 150 views
0

我想在.then()內做一個http帖子。我已經以許多不同的方式...沒有任何工作 我試圖創建一個用戶,然後做一個http POSThttp post .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); 

}; 
}; 

我想在POST

回答

2

發送電子郵件和密碼,您可以在承諾鏈返回的承諾。我會使用promisified請求在這裏做postAsync。

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);