firebase - 将本地模拟器用于带有 expo 的 firebase
问题描述
我正在尝试使用 firebase 在本地进行模拟,以测试我正在使用 expo 开发的 react 本机应用程序。为此,我正在尝试将功能和 Firestore 的主机设置为本地主机上的正确端口。
经过多次迭代,我终于找到了一个奇怪的导入和调用组合,没有出错。但是,当我尝试使用 expo 运行它时,我的应用程序出现了一个没有错误的空白屏幕。在这一点上我很迷茫,firebase 文档令人困惑。
这是我当前的 index.js:
import firebase from "firebase"
import 'firebase/firestore';
import 'firebase/functions';
import 'firebase/app';
const config = {
//config info
};
const fb = firebase.initializeApp(config);
const firestore = firebase.firestore();
const functions = firebase.functions();
if(__DEV__){
firestore.settings({
host : "localhost:9000",
ssl : false
});
functions.useFunctionsEmulator("http://localhost:5001");
}
const auth = fb.auth();
export { auth, functions, firestore }
导入非常奇怪,我不理解它们,但我是从另一个堆栈溢出线程中得到它们的,这是唯一让它甚至到达文件末尾的东西。关于设置本地模拟器,我是否缺少一些非常明显的东西?
解决方案
一起使用 Local Emulator Suite 和 Expo 时可能遇到的问题是“localhost”是指您正在使用的设备。如果您在物理设备上进行测试,则需要将 Firebase 指向您计算机上正在运行的实例。我在这里写了一个简短的解释器:
https://dev.to/haydenbleasel/using-the-firebase-local-emulator-with-expo-s-managed-workflow-5g5k
推荐阅读
- c - scanf 正在覆盖第二个变量
- c# - 使用小写字母的 Python URL 编码?
- c++ - 尝试制作类型转换运算符
- json - 使用 openjson 和/或 json_value 解析 TSQL 中的未知 JSON 路径
- search - Flutter SerachDelegate 修改 Hint Text Color 和 TextField Cursor Color
- join - 在 psql 中加入三个表并根据组成员关系保留结果
- php - 使用 php if 根据用户从上一页的选择显示表单
- javascript - 会话未持续开发(本地主机:4200)
- caching - 是否有类方法或命令可以查看 .gof 文件中的全局变量?以及如何在gof文件中提取特定的全局
- c++ - 使用 http 客户端从 ftp 服务器下载文件