我想使用Google的网站管理员工具为我的“网站”添加域名验证,该网站完全由Firebase的Cloud Functions组成:
https://us-central1-<project-id>.cloudfunctions.net/
但是,我无法弄清楚如何以一种成功运作的方式做到这一点。
推荐的方法是使用验证密钥下载并提供HTML文件。但是,我似乎无法用点创建一个函数。
exports['googleKEY.html'] = functions...
尝试部署时失败。
另一种方法是在我的“主页”中放置元标记,但这也不起作用,因为我似乎无法创建索引页。
exports[''] = functions...
和
exports['index.html'] = functions...
也失败了。
有没有办法通过功能进行域名验证?我很感激指导。
答案 0 :(得分:2)
所以......我想我最终可能有一个解决方案。
没有直接的方法可以验证Firebase功能域(https://*.cloudfunctions.net
)但是,验证Firebase托管域(https://*.firebaseapp.com
)很容易(using verification file)。所以,让我们从那开始吧。
主机中有一个配置选项,用于设置url重写以提供功能。 (Documented here)
这是上面链接的修改示例配置,打开网址https://<your-project-id>.firebaseapp.com/covertFnBigben
以调用函数bigben
。
{
"hosting": {
"public": "public",
// Add the following rewrites section *within* "hosting"
"rewrites": [
{
"source": "/covertFnBigben", "function": "bigben"
}
]
}
}
因此,在成功验证您的Firebase托管域后,您可以使用该域来调用Firebase功能。
答案 1 :(得分:0)
我遇到了同样的问题:我想在Google Search Console中验证我的域所有权。但是该域实际上是Firebase Cloud Functions域(https://*.cloudfunctions.net
)。我今天找到了一个超级简单的解决方案:
1)在Google Search Console中添加属性时,选择方法“ URL前缀”,然后输入您将在步骤3中创建的函数的网址(即https://foobar.cloudfunctions.net/googleDomainVerification
)。
2)选择方法“ HTML标记”并复制元标记。
3)创建一个在Firebase Cloud Function上推送的https函数。别忘了复制第2步中的元标记
exports.googleDomainVerification = functions.https.onRequest((req, res) => {
res.status(200).send('<!DOCTYPE html> <html> <head> YOUR_META_TAG_HERE </head> <body> </body> </html>')
})
4)等一下,然后在Google Search Console上按“验证”
就是这样。现在一切都应该正常了:)