在 Parse.com 的 Cloud Code 上遇到一些代码问题时,用真实代码 VS sudo 代码重新提出问题
/* 我在这里做错了什么?
我不想重新编写所有代码来使用 Parse.Cloud.run,所以我决定创建一个函数来为我做这件事。
错误信息:
更新失败,无法加载触发器。错误是 TypeError: Object # has no method 'request'
*/
Parse.Cloud.define("httpx", function(request, response) {
Parse.Cloud.httpRequest({
url: request.params.url,
method: request.params.method,
headers: request.params.headers
}, {
success: function(httpResponse) {
response.success(httpResponse);
},
error: function(httpResponse) {
response.error(httpResponse);
}
});
});
function sendRequest(path, method, callback) {
if (!initialized) {
throw 'not initialized, call initialize(username, password) first before calling the API';
}
// Allows for only 2 paramiters to be passed if no method passed.
if (typeof method == 'function') {
callback = method;
method = 'GET';
}
var type = (useHttps) ? 'http://' : 'https://';
////////////////////////////////////////
var request = Parse.Cloud.run("httpx", {
url: type + 'rest.website.com/' + path,
method: method,
headers: headers
}, {
success: function(httpResponse) {
if (callback) {
callback(httpResponse.text);
}
response.success(httpResponse.text);
},
error: function(httpResponse) {
callback(httpResponse.status);
response.error('Request failed with response code ' + httpResponse.status);
}
});
//////////////////////////////////////////
}