Cloud Functionsのリージョンを変更する(ウェブバージョン9)

Cloud Functionsのリージョンはデフォルトではus-central1で実行される。

下記のようにregionパラメータでリージョンを設定すれば、関数が実行されるリージョンを変更できる。

constfunctions = require("firebase-functions");

exports.helloWorld = functions
  .region('asia-northeast1')
  .https.onCall((data, context) => {
  return"Hello from Firebase!!";
});
呼び出し可能関数のリージョンを変更するにはこちらのページに書かれているように下記のようにすれば変更できたが、ウェブバージョン9になってやり方が変わったのでメモ。
var functions = firebase.app().functions('asia-northeast1');
ウェブバージョン9の場合は下記のようにして関数を実行する。
import { getFunctions, httpsCallable } from'firebase/functions';
import { initializeApp, } from"firebase/app";

const firebaseConfig = {
  apiKey: "### APIKEY ###",
  authDomain: "### APIKEY ###",
  projectId: "### APIKEY ###",
  storageBucket: "### APIKEY ###",
  messagingSenderId: "### APIKEY ###",
  appId: "### APIKEY ###"
};

constapp = initializeApp(firebaseConfig);

const functions = getFunctions(app, 'asia-northeast1');
const helloWorld = httpsCallable(functions, 'test');
helloWorld().then((result) => {
  console.log(result);
});
IT技術ブログ
↓↓「にほんブログ村」のランキングに参加しています。少しでも面白い、参考になったとか思われたらポチッとしていただけると嬉しいです!
にほんブログ村 IT技術ブログへ
にほんブログ村