firebase模拟器调用生产firestore而不是仿真firestore



我的函数模拟器正在调用生产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   │
以下是我在函数中配置应用程序和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
}
}

我遇到这个问题的原因是因为我是一个dum dum。

更技术性的原因是,我试图在我的云功能中初始化firebase,就好像它是一个外部应用程序一样(它使用"firebase/app"包).

在云功能中初始化firebase的正确方法是使用"firebase-admin"此包还包含firestore和您需要的所有其他功能。

最新更新