【问题标题】:Firebase Cloud Function is not accessible to the public [An application is requesting permission to access your Google Account.]公众无法访问 Firebase Cloud Function [应用程序正在请求访问您的 Google 帐户的权限。]
【发布时间】:2021-03-05 20:21:59
【问题描述】:

我刚刚将 Express 与 Firebase Cloud Functions 一起使用并创建了一个端点。

app.get('/time', (req, res) => {
    const date = new Date();
    const hours = (date.getHours() % 12) + 1;  // London is UTC + 1hr;
    res.json({bongs: 'BONG '.repeat(hours)});
});

端点可通过以下路径公开访问:

https://<region>-<project-name>.cloudfunctions.net/app/time

app 来自入口源 index.js:

exports.app = functions.region('asia-east2').https.onRequest(app);

但是,它无法通过路径访问:

https://<project-name>.web.app/app/time

默认情况下,它需要我授予权限并选择我的 Google 帐户。怎么会?端点供公众访问。

我是否错过了任何设置以及如何解决此问题?

如果我不使用 Express Framework,以上 2 条路径都可供公众访问。 (即从您的应用调用函数,https://firebase.google.com/docs/functions/callable

谢谢~

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    无法访问的路径表示您正在尝试使用 Firebase 托管访问 Cloud Functions。当访问您的函数时出现问题时会出现该错误。只是给你一个想法,这里有一个类似错误的线程:

    firebase SSR problem, "App requesting permission to access your google account" pops up instead of website

    重要提示:在了解解决方案之前,您必须知道 Firebase Hosting 目前支持 us-central1 中的云函数。您不能将任何其他区域用于您的功能,例如 asia-east2。

    接下来,您需要在托管部分设置重写规则,以提供您在 Express 应用上配置的子路径:

    firebase.json

    "hosting": {
      "public": "public",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],  
      "rewrites": [ {
        "source": "/time",
        "function": "app"
      } ]
    }
    

    如果你这样做正确,你应该可以通过这个路径访问你的函数:

    https://<project-name>.web.app/time
    

    请注意,Firebase 托管中的路径是 /time,而不是 /app/time


    参考:https://firebase.google.com/docs/hosting/functions#use_a_web_framework

    【讨论】:

    • 哦...这就是为什么我无法通过主机访问的原因,因为我的是 asia-east2...我希望 Firebase 可以尽快支持更多区域。
    猜你喜欢
    • 1970-01-01
    • 2022-09-28
    • 2021-08-01
    • 1970-01-01
    • 2014-09-27
    • 2020-05-06
    • 1970-01-01
    • 2020-10-17
    • 2020-06-29
    相关资源
    最近更新 更多