在本地运行云功能时,firebase-database
是否会获取数据?
这在部署时工作得非常好,但在本地计算机上根本不能正常工作。
以下是我的代码的样子:
const readAndWriteToFirebase = async (payload, admin1) => {
const dmac = Object.keys(payload)[0];
try {
console.log('got called')
const db = admin.database()
const ref = db.ref(`users/${dmac}`);
const snapshot = await ref.once('value')
console.log(snapshot.val())
} catch (error) {
// do some fancy thing with the error here
console.error(error)
}
}
// this function is calling the above function
export const subscribeToPubSub = functions.pubsub.topic('not-test').onPublish(async (event, context) => {
const pubSubMessage = event.json;
try {
// JSON.stringify(pubSubMessage);
// admin.initializeApp();
const firebasePayload = parseTopicPayload(pubSubMessage);
console.log(firebasePayload)
return readAndWriteToFirebase(firebasePayload, admin)
} catch (e) {
console.error('PubSub message was not JSON', e);
return e
}
});
现在在本地运行它:
npm start
“开始”:“导出GOOGLE_APPLICATION_CREDENTIALS = \”/ home / haroonkhan / Workspace / Personal / Dev / abc-functions / functions / secret / abc-beta-12345678.json \“; npm run shell”,
控制台中没有关于database
的内容。
此函数在我的pub-sub触发器云函数上调用,它从firebase-database
获取数据。
是的,我已经从here下载了服务帐户密钥,在本地成功运行了pub-sub触发器功能。
我在这里遗漏了什么吗?