我有三个Firebase项目,分别代表在Firebase托管上托管的开发,登台和生产环境.每个环境都利用自己部署的Firebase功能,如下所示:
I have three Firebase projects representing Development, Staging and Production environments hosted on Firebase hosting. Each environment utilizes its own deployed Firebase functions like so:
- Dev函数端点: us-central1-my-app -dev.cloudfunctions/someFunction
- 分段功能端点: us-central1-my-app -staging.cloudfunctions/someFunction
- 生产功能端点: us-central1-my-app.cloudfunctions /someFunction
- Dev function endpoint: us-central1-my-app-dev.cloudfunctions/someFunction
- Staging function endpoint: us-central1-my-app-staging.cloudfunctions/someFunction
- Production function endpoint: us-central1-my-app.cloudfunctions/someFunction
我无法弄清楚静态的,由Firebase托管的客户端React应用程序应如何调用这些函数,因为每个URI端点都根据执行代码的环境而变化.
I can't figure out how the static, Firebase-hosted client React application should invoke these functions because the URI endpoints of each changes depending on which environment the code is executing from.
理想情况下,我可以为每个Firebase托管环境设置特定于环境的配置;不幸的是,在Firebase托管中执行此操作的唯一方法是在Firebase Functions本身内部
Ideally I could set environment-specific configuration for each Firebase Hosting environment; unfortunately the only way to do this in Firebase Hosting is from within Firebase Functions themselves.
如何为每个Firebase功能检索特定于环境的终结点?
How can I retrieve the environment-specific endpoint for each Firebase Function?
推荐答案您在这里有几个选择.
首先,您可以按照自己喜欢的任何方式配置React应用.每个系统组件(后端,前端)都有自己的配置不一定不是一件坏事.
First, you could just configure your React app any way you like. It's necessarily not a bad thing for each system component (backend, frontend) to have its own configuration.
第二,由于您使用Firebase Hosting提供静态内容,因此您也可以使用它来为您的函数提供API端点.这意味着您的静态内容和API终结点都通过相同的主机名提供服务,这意味着您在发出请求时不再需要指定主机.所有请求都可以相对于该主机.您可以通过托管重写规则来实现此目的.
Second, since you're using Firebase Hosting to serve your static content, you can also use it to serve your functions API endpoints. This means that both your static content and API endpoints are all served through the same hostname, which means you no longer have to specify the host when making a request. All the requests can be relative to that host. You can achieve this via Hosting rewrite rules.
更多推荐
如何从Firebase托管应用程序访问特定于环境的Firebase功能端点?
发布评论