golang中的google cloud function gen2在firebase路由上的认证问题

vuv7lop3  于 2023-01-27  发布在  Go
关注(0)|答案(1)|浏览(167)

我在测试go gen2的google cloud函数,函数的代码部署的不错,运行的不错,一切都很好,函数名为readrequest,对所有人开放,可以访问https://readrequest-v7disnxdea-uc.a.run.app
我还添加Map到一个专用子域没有问题。
现在我尝试在一个web firebase应用程序中进行路由,为此我添加了一个到firebase.json的路由
firebase.json中的规则如下所示:

{
  "hosting": {
    "public": "public",
    "rewrites": [

      {
        "source": "/l",
        "function": "l3"
      },
      {
        "source": "/gotest",
        "function": "readrequest"
      },
      {
        "source": "/gotest/**",
        "function": "readrequest"
      },
      {
        "source": "/rc1",
        "function": "rc1"
      },
      {
        "source": "/rc2",
        "function": "rc2"
      },
      {
        "source": "/rc2/**",
        "function": "rc2"
      },
      {
        "source": "/rc1/**",
        "function": "rc1"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

我可以访问这个函数,总是要求认证,但是即使我接受认证也不起作用。我在us-central1中创建了这个函数来避免问题。
错误为:

Error: Forbidden
Your client does not have permission to get URL /readrequest/gotest/asdf from this server.

如果我拼错了函数名,我会得到同样的错误,所以这就像路由器没有找到函数,但不为什么不呢?

pod7payv

pod7payv1#

由于Cloud Functions gen 2运行在Cloud Run之上(url、权限、日志和许多其他内容都是相同的!),因此访问Cloud Functions gen 2的方式不是通常的Cloud Functions gen 1方式,而是Cloud Run方式!
购买方式,替换函数(gen 1)引用"function": "readrequest",函数(gen 2,即Cloud Run)引用"run": { "serviceId": "readrequest", "region": "us-central1" }

相关问题