I'm trying to deploy a cloud function that updates an Algolia Search index whenever a new document is created in my Firestore. Everything seems to start well but then at the very end, it errors out. I've been through the docs and it feels like my syntax is correct so I'm not sure what to do at this point. The Cloud Functions log don't point to anything and just echo the error that I received below
Error Message:
=== Deploying to 'test-ffdbb'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
+ runtimeconfig: all necessary APIs are enabled
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (1.25 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating function onProductCreated...
! functions[onProductCreated]: Deployment error.
Failed to configure trigger providers/cloud.firestore/eventTypes/[email protected] (onProductCreated)
My Code:
const functions = require('firebase-functions');
const algoliasearch = require('algoliasearch');
// App ID and API Key are stored in functions config variables
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_INDEX_NAME = "Firestore";
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
// Update the search index every time a blog post is written.
exports.onProductCreated = functions.firestore
.document("Product Catalog/{id}")
.onCreate(event => {
const product = event.data.data();
product.objectID = event.params.postId;
const index = client.initIndex(ALGOLIA_INDEX_NAME);
return index.saveObject(product);
});
package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"@google-cloud/firestore": "^0.8.2",
"algoliasearch": "^3.24.5",
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1"
},
"private": true
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…