将功能模拟器与实时数据库一起使用

时间:2020-03-20 10:02:11

标签: firebase google-cloud-firestore google-cloud-functions firebase-cli

为了轻松测试https可调用函数,我想以一种可以评估在线数据库的方式运行函数模拟器。

启动仿真器的方式是这样的:

"GOOGLE_APPLICATION_CREDENTIALS=\"/path/to/credentials.json\" firebase emulators:start --only functions"

现在,我仍然需要将应用程序中的firebase函数配置指向仿真器的主机/端口。

有办法吗?

对于Firestore,您可以执行以下操作:

  const db = firebaseApp.firestore();

  if (window.location.hostname === "localhost") {
    console.log("localhost detected!");
    db.settings({
      host: "localhost:8080",
      ssl: false
    });
  }

是否有类似的方法来配置Firebase功能以指向模拟器?

我知道您可以通过functions-shell测试功能,但是我觉得不太方便。我想将我的应用程序与Firestore中的可用数据一起使用。

1 个答案:

答案 0 :(得分:1)

这不是受支持的用例。您可以使用云服务或本地仿真器,不能同时使用两者。您可以尝试使用可以从云中获取的一些数据来预填充仿真器,仅此而已。 (本地仿真器的目的是避免完全需要云服务。)