首页 > 解决方案 > 如何验证 Firebase 函数?

问题描述

我想向 Google Cloud PubSub 推送订阅添加一个 webhook。我的 webhook url 端点是一个 Firebase 函数。要发布到我的 Firebase 端点,我必须验证域。

我的问题是 Firebase Functions 似乎没有办法静态托管单个网站。Firebase 托管发生在一个完全不同的域中。

所拥有的(来自 Firebase 托管):

https://[PROJECT-ID].firebaseapp.com/[GOOGLE-FILE].html

需要什么(来自 Firebase Functions):

https://us-central1-[PROJECTID].cloudfunctions.net/[Google-FILE].html

标签: firebasegoogle-cloud-platformfirebase-hostinggoogle-cloud-pubsub

解决方案


我通过express.static在包含要在我的“./functions”目录中验证的 Google HTML 的文件夹上使用解决了这个问题。

Google 确实应该考虑允许他们的静态站点托管选择性地部署到功能域中的指定路由,而不是纯粹通过单独的域。

类似于以下内容:

...
constructor() {
    this.express = express();

    // place your google verification HMTL file in the directory to expose
    // in my case, 'www'
    this.express.use(express.static(join(__dirname, '../..', 'www')));

然后部署您的功能。


推荐阅读