我在 Angular Firebase 项目中使用 ProvideFunctions 函数来初始化应用程序的云函数。但是,我需要添加更多区域来支持我的应用程序的全球用户群。目前,我的代码如下所示:
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getApp, getFunctions, connectFunctionsEmulator } from 'firebase/app';
import { connectFunctionsEmulator as connectFunctionsEmulatorCore, getFunctions as getFunctionsCore } from 'firebase/functions';
import { environment } from '../environments/environment';
export const provideFunctions = () => {
const functions = getFunctionsCore(getApp(), 'asia-southeast2');
if (environment.useEmulators) {
connectFunctionsEmulatorCore(functions, 'localhost', 5001);
}
return functions;
};
此代码初始化 asia-southeast2 区域的 Cloud Functions。如何修改此代码以添加对多个区域的支持,例如 us-central1 和 europe-west1?我需要能够根据用户的位置调用适当的云功能。
我尝试寻找解决方案,但找不到明确的方法来实现这一目标。任何帮助或指导将不胜感激。
您必须为每个区域调用
initializeApp()
一次,然后使用每个生成的 FirebaseApp 对象来获取该区域的新 Functions 对象(使用您的 getFunctionsCore()
函数)。
然后,您必须根据要运行的区域弄清楚您的应用程序将如何使用每个独立配置的 Functions 对象。