您好,我试图在此处设置algolia以与我的Firebase数据库一起使用,但遇到了一些麻烦。我逐步遵循了本指南。
https://www.algolia.com/doc/tutorials/indexing/3rd-party-service/firebase-algolia/
但是,当我尝试运行它时仍然出现此错误
'Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail and then I comment out this line.'
我不确定我的代码有什么问题,但我仍然遇到了问题。我已经从index.js中包含了一些代码,以查看是否有人可以看到我做错的事情。
const functions = require('firebase-functions');
const algoliasearch = require('algoliasearch');
const dotenv = require('dotenv');
const firebase = require('firebase');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// load values from the .env file in this directory into process.env
dotenv.load();
// Initialize Firebase
var config = {
apiKey: "AIzaSyA25OPWS1ign1vKkg7_MFo5SwtqSBezpoo",
authDomain: "eventful-3d558.firebaseapp.com",
databaseURL: process.env.FIREBASE_DATABASE_URL,
projectId: "eventful-3d558",
storageBucket: "eventful-3d558.appspot.com",
messagingSenderId: "323022069474"
};
firebase.initializeApp(config);
const database = firebase.database();
// configure algolia
const algolia = algoliasearch(
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY
);
const index = algolia.initIndex(process.env.ALGOLIA_INDEX_NAME);
// Get all contacts from Firebase
database.ref('/events').once('value', event => {
// Build an array of all records to push to Algolia
const records = [];
event.forEach(event => {
// get the key and data from the snapshot
const childKey = event.key;
const childData = event.val();
// We set the Algolia objectID as the Firebase .key
childData.objectID = childKey;
// Add object for indexing
records.push(childData);
});
// Add or update new objects
index
.saveObjects(records)
.then(() => {
console.log('records are', records);
console.log('Events imported into Algolia');
})
.catch(error => {
console.error('Error when importing events into Algolia', error);
process.exit(1);
});
});