Guest User

Untitled

a guest
Apr 27th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. TypeError: Cannot read property 'val' of undefined
  2. at exports.indexPostsToElastic.functions.database.ref.onWrite.event (/user_code/index.js:13:27)
  3. at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
  4. at next (native)
  5. at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
  6. at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
  7. at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
  8. at /var/tmp/worker/worker.js:710:26
  9. at process._tickDomainCallback (internal/process/next_tick.js:135:7)
  10.  
  11. const functions = require('firebase-functions');
  12. const request = require('request-promise')
  13. exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')
  14.  
  15. .onWrite( event => {
  16.  
  17. let postData = event.data.val();
  18.  
  19. let post_id = event.params.post_id;
  20.  
  21.  
  22. console.log('Indexing post:', postData);
  23.  
  24.  
  25. let elasticSearchConfig = functions.config().elasticsearch;
  26.  
  27.  
  28. let elasticSearchUrl = elasticSearchConfig.url + 'posts/post/' + post_id;
  29.  
  30.  
  31. let elasticSearchMethod = postData ? 'POST' : 'DELETE';
  32.  
  33.  
  34.  
  35. let elasticSearchRequest = {
  36.  
  37. method: elasticSearchMethod,
  38.  
  39. url: elasticSearchUrl,
  40.  
  41. auth:
  42. {
  43.  
  44. username: elasticSearchConfig.username,
  45.  
  46. password: elasticSearchConfig.password,
  47.  
  48. },
  49.  
  50. body: postData,
  51.  
  52. json: true
  53.  
  54. };
  55.  
  56.  
  57. return request(elasticSearchRequest).then(response =>
  58. {
  59.  
  60. console.log("ElasticSearch response", response);
  61.  
  62. return null;
  63. });
  64. });
  65.  
  66. {
  67. "name": "functions",
  68. "description": "Cloud Functions for Firebase",
  69. "scripts": {
  70. "lint": "eslint .",
  71. "serve": "firebase serve --only functions",
  72. "shell": "firebase functions:shell",
  73. "start": "npm run shell",
  74. "deploy": "firebase deploy --only functions",
  75. "logs": "firebase functions:log"
  76. },
  77. "dependencies": {
  78. "firebase-admin": "~5.12.0",
  79. "firebase-functions": "^1.0.1",
  80. "request": "^2.85.0",
  81. "request-promise": "^4.2.2"
  82. },
  83. "devDependencies": {
  84. "eslint": "^4.12.0",
  85. "eslint-plugin-promise": "^3.6.0"
  86. },
  87. "private": true
  88. }
Add Comment
Please, Sign In to add comment