Firebase ReferenceError:未定义PostData

问题描述 投票:0回答:1

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

我希望函数执行完成状态成功,但最终会出错。

node.js firebase
1个回答
0
投票

改变这个:

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

进入:

console.log('Indexing post', postData);
© www.soinside.com 2019 - 2024. All rights reserved.