Я использую Typescript с nodejs. У меня есть callback function
, и я получаю данные как объект в теле, когда я консоль. Я хочу передать данные в ключ данных ctx.body
. Могу ли я сделать sh то object
в другом variable
и затем перейти к ctx.body
?
router.post('/api/send_otp', async (ctx: Koa.Context, next: () => Promise<any>) => {
var phone = ctx.request.body.phone;
if (!phone) {
ctx.body = {
message: "Please enter phone number",
};
} else {
var options = {
url: '',
method: 'POST',
auth: {
'user': '',
'pass': ''
},
};
const callback = function(error, response, body) {
if (response) {
console.log(body); // Getting data here
}else{
console.log('error',error);
}
};
request(options,callback);
ctx.body = {
data: body, //I want data here
}
});