Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- 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;
- });
- });
- {
- "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
- }
Add Comment
Please, Sign In to add comment