LOs*_*KeY 27 firebase google-cloud-functions
有没有办法指定将部署我的firebase功能的区域/区域.
实际上我没有在文档中找到任何关于它的内容,我的功能总是部署到我们 - central1但我希望在eu-central1上有...
是否可以在Firebase - Config - File中设置它?
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我也看了一下cli选项,但我没有找到任何东西.
Firebase项目本身已正确设置为欧洲区域oO
提前致谢
Fra*_*len 26
这里有一个firebaser
更新(2018-07-25):
现在,您可以在Firebase中指定云功能的区域,在代码中指定该区域并部署更改.例如:
exports.myStorageFunction = functions
.region('europe-west1')
.storage
.object()
.onFinalize((object) => {
// ...
});
Run Code Online (Sandbox Code Playgroud)
有关完整详细信息,请参阅有关云功能位置的Firebase文档(从中获取上述代码段)并修改已部署功能的区域.
Moe*_*Moe 21
更新于 2024 年 2 月
使用新的 V2 语法,添加 .region 不起作用,并且在开头添加 {region: ''} 对象也不适用于 onDocument 事件。
更新 V2 firebase 函数区域的解决方法是更新全局选项以更改区域,这也会自动将任何函数默认为您指定的区域:
const { setGlobalOptions } = require("firebase-functions/v2");
setGlobalOptions({ region: 'europe-west1' });
Run Code Online (Sandbox Code Playgroud)
此外,如果您想编辑任何其他选项,它将始终默认为您在 setGlobalOptions() 中定义的内容
const { setGlobalOptions } = require("firebase-functions/v2");
setGlobalOptions({
maxInstances: 10,
region: "europe-west1",
timeoutSeconds: 60,
memory: "2GiB",
});
Run Code Online (Sandbox Code Playgroud)
Jac*_*ckl 11
来自docs:https://firebase.google.com/docs/functions/locations
现在可在以下地区使用:
// 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");
});
Run Code Online (Sandbox Code Playgroud)
要为您的所有功能使用相同的自定义区域,您可以执行以下操作。
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!");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8235 次 |
| 最近记录: |