我需要父级post方法中子级的响应。 Promise或回调有什么办法吗?
const cardRoutes = (app, logger) => {
const request = require('request');
// CREATE
app.post('/payment', (req, res) => {
var currencyCode = req.body.currencyCode;
var amount = req.body.amount;
try {
const options = {
url: 'www.testsite.com',
json: true,
headers:{'content-type' : 'application/json'},
body: {
amount: amount,
currency: currencyCode
}
};
request.post(options, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(res.body.transactionId);
console.log(`Status: ${res.statusCode}`);
res.end();
});
res.statusCode = 200;
res.json({message:"okay message"});
} catch (e) {
logger.error("Error: " + e.message);
res.end();
return;
}
});
};
module.exports = cardRoutes;