如何从Firebase托管应用程序访问特定于环境的Firebase功能端点? [英] How to access environment-specific Firebase Function endpoints from Firebase Hosted application?

查看:82
本文介绍了如何从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 function endpoint: https://us-central1-my-app-dev.cloudfunctions.net/someFunction
  • Staging function endpoint: https://us-central1-my-app-staging.cloudfunctions.net/someFunction
  • Production function endpoint: https://us-central1-my-app.cloudfunctions.net/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提供静态内容,因此您也可以使用它来

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功能端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆