我能够使用指令在本地通过应用程序连接到firebase firestore仿真器,在这里。示例代码仅包括一个这样的评论:
// Firebase previously initialized using firebase.initializeApp().
仅描述一种使用它的方法 - 通过将生产配置传递到 initizeapp
,这就是我让它工作的方式。
但是,我正在尝试在独立的Docker环境中运行该应用程序,以进行连续集成。我不希望在此版本的构建中与生产有关的任何配置。根据生产,我的意思是任何可能涉及燃烧账单的参考。有没有一种方法可以在没有生产参考的情况下调用 initizeApp
?还是还有其他处理CI构建的方法?
I am able to connect to Firebase firestore emulator from a create-react-app
app locally using the instructions here. The example code simply includes a comment like this:
// Firebase previously initialized using firebase.initializeApp().
The API reference for initializeApp describes only one way of using it - by passing production configuration to initializeApp
and that's the way I got it to work.
However, I am trying to run the app in a self-contained docker environment for the purpose of continuous integration. I do not want any config related to production in this version of the build. By production, I mean any reference that might count towards firebase billing. Is there a way to call initializeApp
without production reference? Or are there other ways to handle CI builds?
发布评论
评论(2)
测试后,您应使用Apikey上的任何字符串初始化应用程序:
After some testing, you should initialize app with any string on apiKey:
为此,我们需要使用演示应用程序,如此答案中所述。一旦我们启动了该答案中描述的模拟器,就可以像这样调用
initializeApp
:这里使用的 projectId 需要与启动模拟器时使用的项目 ID 相匹配,并且需要以
demo 启动
。这可确保应用程序不会意外连接到生产服务。否决后更新:
我在此处审查了我的项目作品。这是我使用的配置:
这应该可以解决注释中的问题。我没有提到我们可以使用随机 apiKey 并且模拟器并不关心。请注意,对我有用的版本是
9.6.10
。We need to use a demo app for this purpose, as explained in this answer. Once we start the emulators described in that answer,
initializeApp
can be invoked like so:The projectId used in here need to match the one used when starting up the emulator and it needs to start with
demo
. This ensures there is no way for the app to connect to production services accidentally.Update after downvotes:
I reviewed my project here and it works. Here's the config I have used:
This should address the problems in the comments. I failed to mention that we can use a random apiKey and the emulators don't care. Please note the version that worked for me is
9.6.10
.