【发布时间】:2020-07-28 05:24:16
【问题描述】:
我一直在尝试实现一些从 Cloud Firestore 读取数据的 Cloud Functions。我想在本地测试这些,但是我无法运行 Cloud Firestore 模拟器。我的假设是问题出在哪里,但可能在其他地方 - 如果是这样,请告诉我。
这是我的功能:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
admin.initializeApp()
//Functions to fetch the documents in the user collection and send them to the client.
export const getUserDocs = functions.https.onRequest((request, response) => {
admin.firestore().doc('/Users/{documentId}').get()
.then(snapshot => {
const data = snapshot.data()
response.send(data)
})
.catch(error => {
response.status(500).send(error)
})
})
这是我在运行命令firebase serve --only functions 时遇到的错误:
Carlo@Carlos-Air-2 functions % firebase serve --only functions
⚠ Your requested "node" version "8" doesn't match your global version "13"
✔ functions: functions emulator started at http://localhost:5000
i functions: Watching "/Users/Carlo/app/functions" for Cloud Functions...
✔ functions[getUserSports]: http function initialized (http://localhost:5000/app/us-central1/getUserSports).
i functions: Beginning execution of "getUserSports"
⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠ External network resource requested!
- URL: "http://179.252.163.233/computeMetadata/v1/instance"
- Be careful, this may be a production service.
⚠ External network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
- Be careful, this may be a production service.
i functions: Finished "getUserSports" in ~9s
我尝试重新从头开始并卸载并重新安装,但没有成功。 我也在 YouTube 上观看了教程系列,但由于某种原因,我的代码无法正常工作。
非常感谢任何帮助。
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions firebase-cli