我的函数仿真器正在调用生产firestore,而不是firestore仿真器。我不确定这是怎么发生的,因为我听说这是不可能的。
我已经设置了我的模拟器和firestore模拟器加载:
Emulator │ Host:Port │ View in Emulator UI │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ 127.0.0.1:9099 │ http://127.0.0.1:4000/auth │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Hosting │ 127.0.0.1:5000 │ n/a │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Storage │ 127.0.0.1:9199 │ http://127.0.0.1:4000/storage │
下面是我如何在函数中配置app和firestore:
import { initializeApp } from 'firebase/app';
import {
getFirestore,
} from 'firebase/firestore';
let firebaseConfig = {
databaseURL: 'http://localhost:8080?ns=nft-public',
projectId: 'nft-public',
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
和我在firebase.json中的模拟器选项
"emulators": {
"auth": {
"host": "localhost",
"port": "9099"
},
"firestore": {
"host": "localhost",
"port": "8080"
},
"functions": {
"host": "localhost",
"port": "5001"
},
"hosting": {
"port": 5000
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
}
}
发布于 2021-10-02 21:40:59
我有这个问题的原因是因为我是一个哑巴。
更多的技术原因是我试图在我的云函数中初始化firebase,就像它是一个外部应用程序一样(它使用"firebase/ app“包)。
在云函数中初始化firebase的正确方法是使用"firebase-admin“。此包还包含firestore和您需要的所有其他功能。
https://stackoverflow.com/questions/69402121
复制相似问题