【问题标题】:Setting deploy region in firebase configuration file在 Firebase 配置文件中设置部署区域
【发布时间】:2020-05-06 11:06:46
【问题描述】:

在使用firebase.json.firebaserc 文件将功能部署到firebase 时,是否可以定义使用哪个区域?与此相关的文档似乎并不明确。

使用 GitHub Actions 部署 firebase 函数,并希望尽可能避免在代码本身中添加区域。

建议?

【问题讨论】:

    标签: firebase google-cloud-platform google-cloud-functions


    【解决方案1】:

    使用您提到的配置是不可能的。必须使用提供的 API 在代码中同步定义区域。您也许可以在 index.js 的全局范围内使用 fs.readFileSync() 拉入一个外部 JSON 文件,解析其内容,并将它们应用到函数构建器。 (请注意,您必须同步地进行此操作 - 您不能使用返回承诺的方法。)

    【讨论】:

    • 感谢您的回复。有点糟糕,这不能在配置 c_c 中定义
    • 您可以随时提出功能请求。 support.google.com/firebase/contact/support
    • 我使用 Angular + SSR 并通过 Cloud Functions 部署应用程序。当我运行 firebase deploy 时,会生成文件 index.js 并且它包含的函数使用 us-central1 作为默认区域。我可以以任何方式自定义这个生成的文件吗?例如。将区域设置为europe-west3
    【解决方案2】:

    我已经使用本机函数配置解决了这个问题。
    示例:

    firebase functions:config:set functions.region=southamerica-east1
    

    然后在函数声明中我如下:

    const { region } = functions.config().functions;
        
    exports.myFunction = functions.region(region).https.onCall((data) => {
      // do something
    });
    

    这样,每次我需要一个不同的区域时,它只需要一个新的配置集。

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 2020-10-06
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多