我正在测试go gen2 google cloud功能,该功能的代码部署ok,它工作ok,一切都很好。这个函数名为readrequest,对所有人开放。你可以到达https://readrequest-v7disnxdea-uc.a.run.app
我还添加映射到专用子域没有问题。
现在我正在尝试路由在一个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.
如果我拼错了函数名,我得到同样的错误,所以它就像路由器没有定位函数,但不知道为什么。
因为Cloud Functions gen2运行在Cloud Run之上(url,权限,日志和许多其他东西都是相同的!),所以到达Cloud Functions gen2的方式不是通常的Cloud Functions gen1方式,而是Cloud Run方式!
这样,替换函数(gen1)参考"function": "readrequest"
,函数(gen2,即Cloud Run)参考"run": { "serviceId": "readrequest", "region": "us-central1" }