Я пытаюсь создать функцию 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)
Я ожидаю, что выполнение функции завершится при успешном статусе, но завершается с ошибкой.