我正在开发一个flutter应用程序。我试图在开发过程中使用Firebase模拟器作为后端。
我配置了仿真器,当我使用"firebase emulators:start"命令时,我确认了以下响应。
仿真器主机:仿真器UI中的端口视图
身份验证0.0.0.0:9099| http://127.0.0.1:4000/auth
函数0.0.0.0:5001| http://127.0.0.1:4000/functions
文件名:|http://127.0.0.1:4000/firestore
存储器0.0.0.0:9199| http://127.0.0.1:4000/storage
因此,我编写了初始化Firebase设置的部分,如下所示。
Future initializeApp() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseAuth.instance.useAuthEmulator("0.0.0.0", 9099);
FirebaseFunctions.instance.useFunctionsEmulator("0.0.0.0", 5001);
FirebaseStorage.instance.bucket = 'default-bucket';
FirebaseStorage.instance.useStorageEmulator("0.0.0.0", 9199);
FirebaseFirestore.instance.useFirestoreEmulator("0.0.0.0", 8080);
FirebaseFirestore.instance.settings = const Settings(
host: "0.0.0.0",
persistenceEnabled: false,
sslEnabled: false,
);
}
我的firebase.json在下面
{
"functions": {
"predeploy": "npm --prefix \"$RESOURCE_DIR\" run build",
"source": "functions"
},
"emulators": {
"auth": {
"host": "0.0.0.0",
"port": 9099
},
"functions": {
"host": "0.0.0.0",
"port": 5001
},
"firestore": {
"host": "0.0.0.0",
"port": 8080
},
"storage": {
"host": "0.0.0.0",
"port": 9199
},
"ui": {
"enabled": true
}
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
}
}
但当我尝试使用firestore时,它显示"未处理的异常:[cloud_firestore/unavailable]服务当前不可用。这很可能是暂时情况,可以通过回退重试来更正。"。
我想我已经把所有的设置都做好了。我想不出是哪一部分错了。希望帮助
下面是firestore-debug.log文件。
Nov 25, 2022 9:34:42 AM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://0.0.0.0:9150
API endpoint: http://0.0.0.0:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
export FIRESTORE_EMULATOR_HOST=0.0.0.0:8080
Dev App Server is now running.
Nov 25, 2022 9:34:44 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Nov 25, 2022 9:34:45 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Nov 25, 2022 9:34:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Nov 25, 2022 9:34:48 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Nov 25, 2022 9:35:46 AM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketChannelHandler initChannel
INFO: Connected to new websocket client
Nov 25, 2022 9:35:46 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Nov 25, 2022 9:36:46 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
*** shutting down gRPC server since JVM is shutting down
*** server shut down
奇怪的是,Auth Emulator工作得很好。
1条答案
按热度按时间w8f9ii691#
我找到了答案。我不得不改变代码的顺序。
将此代码更改为以下代码:
我想,我需要先设置“FirebaseFirestore.示例.设置“,然后再设置“FirebaseFirestore.示例.使用FirestoreEmulator”