TypeError: Невозможно прочитать свойство 'val' неопределенной Firebase в Android - PullRequest
0 голосов
/ 25 апреля 2018

Я использую сервис Google Cloud в своем проекте Firebase, и сервис, которым я пользуюсь - Elasticsearch.Итак, я успешно развернул проект в своем проекте Firebase, но проблема заключается в том, что всякий раз, когда я запускаю свою функцию, это происходит как ошибка в моем журнале функций firebase-

TypeError: Cannot read property 'val' of undefined
at exports.indexPostsToElastic.functions.database.ref.onWrite.event (/user_code/index.js:13:27)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:710:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Это мой индекс.js-файл, который я написал:

const functions = require('firebase-functions');
const request = require('request-promise')
exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')

    .onWrite( event => {

    let postData = event.data.val();

    let post_id = event.params.post_id;


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


    let elasticSearchConfig = functions.config().elasticsearch;


    let elasticSearchUrl = elasticSearchConfig.url + 'posts/post/' + 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 => 
            {

                 console.log("ElasticSearch response", response);

                 return null;
      });
});

И это мой файл package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1",
    "request": "^2.85.0",
    "request-promise": "^4.2.2"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...