【问题标题】:Firebase - Functions does not allow me to set regionFirebase - 功能不允许我设置区域
【发布时间】:2020-07-31 08:31:24
【问题描述】:

我正在尝试设置一个区域来部署我的功能。根据我必须做的文件:

var functions = firebase.app().functions('us-west2');

但是当我这样做然后尝试部署时,我得到一个错误:

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'onCall' of undefined

如果我将函数定义改回默认值:

const functions = require("firebase-functions");

它有效,知道为什么会出现此错误吗?

示例代码: const firebase = require("firebase"); const admin = require("firebase-admin"); 要求(“firebase 功能”);

firebase.initializeApp({...})

admin.initializeApp()

let functions = firebase.app().functions('us-east1')

exports.findUserInAuth = functions.https.onCall((data, context) => {..}

【问题讨论】:

  • 请编辑问题以提供重现此问题所需的完整、最少的代码。 stackoverflow.com/help/minimal-reproducible-example
  • @DougStevenson 我刚刚添加了示例代码
  • 您的示例代码没有声明firebase,所以它看起来并不完整。另外,我不确定为什么您需要 firebase-funcitons 而不对它返回的对象做任何事情。你需要它来构建你的云函数定义。
  • 忘了复制第一行,我的错。

标签: javascript firebase google-cloud-functions


【解决方案1】:

我认为您阅读文档有误。

如果这是可调用函数的最基本定义,正如documentation 所建议的那样:

const functions = require("firebase-functions");
exports.findUserInAuth = functions.https.onCall((data, context) => {
  // ...
});

然后,要更改区域,您需要在该函数的构建器中插入更多方法调用:

const functions = require("firebase-functions");
exports.findUserInAuth = functions.https.region('us-west2').onCall((data, context) => {
  // ...
});

前端客户端上的代码将使用 firebase-functions。您必须稍后在该页面上使用instructions for setting up the client。在客户端设置区域的工作方式不同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2021-12-07
    • 2020-05-05
    • 2021-10-04
    • 1970-01-01
    • 2011-06-03
    相关资源
    最近更新 更多