如何构建多区域firebase应用程序?



目前,我有这样的结构:

- A couple of functions in a single region
- A firestore database in a single region

前段时间,整个区域宕机,给用户带来了问题。

我想改变结构是在多个区域,数据库和功能。

如何在firebase世界中做到这一点?

请记住,当我在多个区域部署功能时,应该有一些方法将请求路由到靠近用户的区域中的功能。

一旦创建了数据库,就不能更改该区域。您必须创建一个带有新区域的新项目。

默认情况下,函数在us-central1区域运行。如果您有一个函数当前位于us-central1的默认函数区域中,并且您希望将其迁移到asia-northeast1,则需要首先修改源代码以重命名该函数并修改该区域。你可以参考这份文件

// before
const functions = require('firebase-functions');
exports.webhook = functions
.https.onRequest((req, res) => {
res.send("Hello");
});
// after
const functions = require('firebase-functions');
exports.webhookAsia = functions
.region('asia-northeast1')
.https.onRequest((req, res) => {
res.send("Hello");
});

然后运行:

firebase deploy --only functions:newfunction 

用新区域重命名函数后,现在有两个相同的函数在us-central1和asia-northeast1中运行。

你也可以检查这个stackoverflow link1 &Link2可能有帮助

最新更新