Firebase ReferenceError:未定义PostData

时间:2019-04-14 13:39:04

标签: node.js firebase

我正在尝试创建弹性搜索云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)

我希望函数执行成功完成,但状态完成并出现错误。

1 个答案:

答案 0 :(得分:0)

更改此:

console.log('Indexing post', PostData);

对此:

console.log('Indexing post', postData);