如何从Firebase托管应用程序访问特定于环境的Firebase功能端点?

编程入门 行业动态 更新时间:2024-10-28 07:30:04
本文介绍了如何从Firebase托管应用程序访问特定于环境的Firebase功能端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有三个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功能端点?

本文发布于:2023-11-14 02:03:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   功能   环境   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!