如何为 React Native Firebase 设置函数区域
How to set functions region for React Native Firebase
我有一个带有 react-native-firebase 的 React 本机应用程序,我正在尝试 运行 部署到自定义区域的可调用 https firebase 函数。
我读过 firebase.app().functions("MY-REGION")
所以我尝试了以下内容:
import { firebase } from "@react-native-firebase/database"
import functions from "@react-native-firebase/functions"
firebase.app().functions("MY-REGION")
但是如果我 运行 我得到这个错误:
Error: You attempted to use
"firebase.app('[DEFAULT]').functions" but this
module could not be found.
Ensure you have installed and imported the
'@react-native-firebase/functions' package
功能包已安装。
如果我删除 @react-native-firebase/functions
导入,错误保持不变。
如何在 react-native-firebase
中指定 firebase https 函数的区域?
更多尝试:
firebase.initializeApp({
...options
})
firebase.app().functions("MY-REGION")
那就是 Error: Firebase App named '[DEFAULT]' already exists
firebase.initializeApp({
...options
}, "APP_NAME")
firebase.app("APP_NAME").functions("MY-REGION")
给予Error: No firebase App 'APP_NAME' has been created - call firebase.initializeApp()
我希望我遗漏了一些微不足道的东西。
一个解决方案是将函数导入从 import functions from "..."
更改为 import "..."
:
import { firebase } from "@react-native-firebase/database"
import "@react-native-firebase/functions" // <--
// call a https firebase function
firebase.app().functions("MY-REGION").httpsCallable('MyFunction')()
请注意,MY-REGION
应设置为所选 httpsCallable 函数的 firebase 函数仪表板中显示的区域。
我找到的修复确实很简单...
我已经在这里分享它,以便它对其他人有用,但欢迎提供更好的解决方案!
我有一个带有 react-native-firebase 的 React 本机应用程序,我正在尝试 运行 部署到自定义区域的可调用 https firebase 函数。
我读过 firebase.app().functions("MY-REGION")
所以我尝试了以下内容:
import { firebase } from "@react-native-firebase/database"
import functions from "@react-native-firebase/functions"
firebase.app().functions("MY-REGION")
但是如果我 运行 我得到这个错误:
Error: You attempted to use
"firebase.app('[DEFAULT]').functions" but this
module could not be found.
Ensure you have installed and imported the
'@react-native-firebase/functions' package
功能包已安装。
如果我删除 @react-native-firebase/functions
导入,错误保持不变。
如何在 react-native-firebase
中指定 firebase https 函数的区域?
更多尝试:
firebase.initializeApp({
...options
})
firebase.app().functions("MY-REGION")
那就是 Error: Firebase App named '[DEFAULT]' already exists
firebase.initializeApp({
...options
}, "APP_NAME")
firebase.app("APP_NAME").functions("MY-REGION")
给予Error: No firebase App 'APP_NAME' has been created - call firebase.initializeApp()
我希望我遗漏了一些微不足道的东西。
一个解决方案是将函数导入从 import functions from "..."
更改为 import "..."
:
import { firebase } from "@react-native-firebase/database"
import "@react-native-firebase/functions" // <--
// call a https firebase function
firebase.app().functions("MY-REGION").httpsCallable('MyFunction')()
请注意,MY-REGION
应设置为所选 httpsCallable 函数的 firebase 函数仪表板中显示的区域。
我找到的修复确实很简单...
我已经在这里分享它,以便它对其他人有用,但欢迎提供更好的解决方案!