如何从Parse.com云代码模块返回响应

how to return a response from a Parse.com Cloud Code Module?

本文关键字:代码 模块 返回 响应 com Parse      更新时间:2023-09-26

从parse.com的例子来看,在cloud/module.js中,我有

module.exports = {
...
search: function(params, options) {
  return Parse.Cloud.httpRequest({
    method: "GET",
    url: "https://externalapi.com"
  }).then(function(httpResponse) {
    console.log(httpResponse.text); //<--- THIS WORKS!
    if (options && options.success) {
      options.success(httpResponse);
    }
  }, function(httpResponse) {
    if (options && options.error) {
      options.error(httpResponse);
    }
  });
}

代码工作正常,我可以在解析代码中看到响应控制台日志。

它说options是未定义的,所以它从不调用options.success

然后,总是返回空

在cloud/main.js 中

Parse.Cloud.define("searchIt", function(request, response) {
  myModule.search({
        near: request.params.near,
        query: request.params.query
  }).then(function(httpResponse) {
    response.success(httpResponse);
  }, function(httpResponse) {
    response.error("Uh oh, something went wrong");
  });
});

我将代码更改为:

  return Parse.Cloud.httpRequest({
    url: 'https://externalapi.com',
    success:function(httpResponse){
    },
    error:function(httpResponse){
    }
  });
}

现在正在使用