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

查看:24
本文介绍了如何从 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:

我无法弄清楚 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 函数本身中.

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 托管来提供静态内容,因此您也可以将其用于 为您的函数 API 端点提供服务.这意味着您的静态内容和 API 端点都通过相同的主机名提供服务,这意味着您在发出请求时不再需要指定主机.所有请求都可以相对于该主机.您可以通过 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天全站免登陆