更改 v2 中可调用的 firebase 云函数的区域

Luc*_*ner 2 node.js firebase google-cloud-platform google-cloud-functions

嘿,我正在尝试升级到 firebase 云函数 v2,但是当尝试更改代码时,我注意到我的函数不再像 v1 那样具有 .region。

这是 v1 版本,我可以在其中调用 .region 并更改它

import * as functions from "firebase-functions";

exports.helloWorld = functions.region("europe-west1").https.onCall(() => {
  functions.logger.info("Hello logs!", { structuredData: true });

  return { text: "Hello from Firebase!" };
});
Run Code Online (Sandbox Code Playgroud)

现在我升级到 v2,但我得到:

Property 'region' does not exist on type 
'typeof import("/.../node_modules/firebase-functions/lib/v2/index")
Run Code Online (Sandbox Code Playgroud)

尝试为 firebase 云功能 v2 实现类似的功能有什么想法吗?

import { https, logger } from "firebase-functions/v2";
import * as functions from "firebase-functions/v2";

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//

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

exports.helloWorld = regionalFunctions.https.onCall(() => {
  logger.info("Hello logs!", { structuredData: true });

  return { text: "Hello ${process.env.PLANET} and ${process.env.AUDIENCE}" };
});
Run Code Online (Sandbox Code Playgroud)

Dha*_*raj 10

您可以在函数的选项中指定,region如下所示:

import { onCall } from "firebase-functions/v2/https";

export const testFunction = onCall({ region: "..." }, (event) => {
  // ...
})
Run Code Online (Sandbox Code Playgroud)