【发布时间】:2018-02-09 05:48:20
【问题描述】:
我从 Azure Functions 开始。我有以下代码:
module.exports = function (context, req)
{
context.log('JavaScript HTTP trigger function processed a request.');
context.log(context.req.body.videoId)
if (context.req.body.videoId =! null)
{
context.log('inicia a obtener comentarios')
const fetchComments = require('youtube-comments-task')
fetchComments(req.body.videoId)
.fork(e => context.log('ERROR', e), p => {
context.log('comments', p.comments)
})
context.res = { body: fetchComments.comments }
}
else {
context.res = {
status: 400,
body: "Please pass a videoId on the query string or in the request body"
};
}
context.done();
};
如何返回 fetchComments 返回的 JSON?
【问题讨论】:
-
我没有使用 Node.js 制作任何函数,但也许您可以将
context.res = ...和context.done();移动到您记录 cmets 的回调函数中? -
我试过了,结果是一样的
标签: javascript node.js azure azure-functions