如何向 Angular Firebase 中的 ProvideFunctions 函数添加更多区域?

问题描述 投票:0回答:1

我在 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?我需要能够根据用户的位置调用适当的云功能。

我尝试寻找解决方案,但找不到明确的方法来实现这一目标。任何帮助或指导将不胜感激。

angular firebase google-cloud-functions angularfire
1个回答
0
投票

您必须为每个区域调用

initializeApp()
一次,然后使用每个生成的 FirebaseApp 对象来获取该区域的新 Functions 对象(使用您的
getFunctionsCore()
函数)。

然后,您必须根据要运行的区域弄清楚您的应用程序将如何使用每个独立配置的 Functions 对象。

© www.soinside.com 2019 - 2024. All rights reserved.