firebase部署到自定义区域(eu-central 1)

bbmckpt7  于 2023-05-18  发布在  其他
关注(0)|答案(6)|浏览(108)

是否有一种方法来指定我的firebase函数将部署的区域/区域。
实际上,我在文档中没有找到任何关于它的东西,我的函数总是部署到us-central1,但我想把它部署到eu-central1上。
是否可以在Firebase - Config - File中设置它?

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我也看了一下cli选项,但我没有发现任何东西在那里。
Firebase项目本身被正确地设置为欧洲区域o.O

hc2pp10m

hc2pp10m1#

  • 我是燃烧者 *

更新(2018-07-25):
现在可以在Firebase中为您的云函数指定区域,您可以在代码中指定该区域并部署更改。例如:

exports.myStorageFunction = functions
    .region('europe-west1')
    .storage
    .object()
    .onFinalize((object) => {
      // ...
    });

有关完整的细节,请参阅Firebase documentation on Cloud Functions locations(我从上面得到的代码片段)和修改部署函数的区域。

lrpiutwd

lrpiutwd2#

来源:https://firebase.google.com/docs/functions/locations
现已在以下地区提供:

  • us-central 1(爱荷华州)
  • us-east 1(南卡罗来纳州)
  • europe-west 1(比利时)
  • 亚洲-东北1(东京)

变更地域的最佳实践

// before
const functions = require('firebase-functions');

exports.webhook = functions
    .https.onRequest((req, res) => {
            res.send("Hello");
    });

// after
const functions = require('firebase-functions');

exports.webhookEurope = functions
    .region('europe-west1')
    .https.onRequest((req, res) => {
            res.send("Hello");
    });
xwmevbvl

xwmevbvl3#

要为所有函数使用相同的自定义区域,请执行如下操作。

import * as functions from 'firebase-functions';

const regionalFunctions = functions.region('europe-west1');

export const helloWorld = regionalFunctions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});

export const helloWorld2 = regionalFunctions.https.onRequest((request, response) => {
 response.send("Hello from Firebase 2!");
});
0aydgbwb

0aydgbwb4#

要使部署到区域的Firebase函数也能在本地仿真中工作,必须初始化客户端如下:

const functions = LOCAL ? firebase.app().functions(/*functionsRegion*/) :  
  firebase.app().functions(functionsRegion);

const fun = functions.httpsCallable('your_function_name');

也就是说,代码是“不”相同的。在模拟案例中添加一个区域会使调用丢失,而不会出错。
LOCAL是一个客户端值,我已经知道,后端是在云中运行,还是设置为本地仿真。
这是一个火的故事,火的故事,火的故事。
firebase-tools 8.6.0,firebase 7.16.1
附录:
以上是针对浏览器的(没有说明)。我已经停止使用httpsCallable s,因为它们需要在线连接。另一方面,通过Firebase数据库进行接口是离线友好的,因此导致更强大的系统。

hk8txs48

hk8txs485#

如果您正在使用新的Firebase模块化SDK,请尝试以下操作:

export const helloWorld = onRequest({ region: 'asia-southeast2' }, (request, response) => {
  logger.info('Hello logs!', { structuredData: true });
  response.send('Hello from Firebase!');
});

可用区域集可在此处找到:https://firebase.google.com/docs/functions/locations#supported_regions

nhaq1z21

nhaq1z216#

"rewrites": [
  {
    "source": "**",
    "run": {
      "serviceId": "<service id>",
      "region": "europe-west1"
    }
  }
]
},

相关问题