我正在尝试创建一个弹性搜索云Firebase函数,但在firebase函数中有一些错误。错误引用了index.js代码,但我不知道哪里出了问题。我在index.js代码中哪里会出错呢??
const functions = require('firebase-functions');
const request = require('request-promise')
exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')
.onWrite((change,context) =>{
let postData = change.after.val();
let post_id = context.params.post_id;
console.log('Indexing post',PostData);
let elasticSearchConfig = functions.config().elasticSearch;
let elasticSearchUrl = elasticSearchConfig.Url + 'posts/' + post_id;
let elasticSearchMethod = postData ? 'POST' : 'DELETE';
let elasticSearchRequest = {
method:elasticSearchMethod,
url: elasticSearchUrl,
auth:{
username : elasticSearchConfig.username,
password : elasticSearchConfig.password,
},
body: postData,
json : true
};
return request(elasticSearchRequest).then(response => {
return console.log("ElasticSearch response", response);
})
});下面是错误在我的Firebase中的读取方式
ReferenceError: PostData is not defined
at exports.indexPostsToElastic.functions.database.ref.onWrite (/user_code/index.js:10:31)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:114:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:144:20)
at /var/tmp/worker/worker.js:827:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)我希望函数执行结束时状态为成功,但结束时出现错误。
发布于 2019-04-14 21:42:17
更改此设置:
console.log('Indexing post', PostData);如下所示:
console.log('Indexing post', postData);https://stackoverflow.com/questions/55675904
复制相似问题