【问题标题】:Firebase Functions is always trying to call us-central1 Functions wether it's initialized with a specific region or notFirebase Functions 总是尝试调用 us-central1 函数,无论它是否使用特定区域进行了初始化
【发布时间】:2021-07-15 18:10:42
【问题描述】:

问题

在我的 JavaScript 项目中,我尝试从客户端调用 firebase 函数。 我目前的问题是,无论我在初始化函数时是否设置了一个区域,调用的 URL(来自 firebase 函数)总是以相同的区域开头。

我的代码

functions.js(Firebase 函数 - 服务器)

exports.recursiveDelete = functions.region('europe-west1')
  .runWith({
    timeoutSeconds: 540,
    memory: '2GB'
  })
  .https.onCall(async (data, context) => {

    // Doing smth.

  });

删除.js(客户端)

const app = firebase.app();
const functions_delete = app.functions("europe-west1");

function deleteArtWork(path, pid) {
    
    var deleteFn = functions_delete.httpsCallable('recursiveDelete');
    deleteFn({ path: path, pid: pid }).then(function(result) {
            logMessage('Delete success: ' + JSON.stringify(result));
            window.location.href = "../";
        }).catch(function(err) {
            logMessage('Delete failed, see console,');
            console.warn(err);
        });

}

Firebase 本身已正确初始化,因为 Firestore 和 Auth 没有问题。

输出

[Error] Preflight response is not successful
[Error] Fetch API cannot load https://us-central1-projectart-jjl.cloudfunctions.net/recursiveDelete due to access control checks.
[Error] Failed to load resource: Preflight response is not successful (recursiveDelete, line 0)
[Error] Unhandled Promise Rejection: ReferenceError: Can't find variable: logMessage

为什么 Firebase 函数总是试图调用 us-central1 函数?

我是不是做错了什么?

感谢您的帮助。

【问题讨论】:

    标签: javascript firebase google-cloud-functions


    【解决方案1】:

    关于HTTP and client-callable functions,“如果您使用 HTTP 函数为 Firebase 托管提供动态内容,则必须使用 us-central1。”

    【讨论】:

      猜你喜欢
      • 2023-02-18
      • 2021-12-13
      • 2021-04-10
      • 2019-01-17
      • 2019-02-17
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      相关资源
      最近更新 更多