Firebase Functions:如何使用Node.js设置函数区域?

huangapple go评论120阅读模式
英文:

Firebase Functions: How to set a function region using Node.js?

问题

I'm using Node.js for my Firebase Functions. Please look at my func below. I want to set this func to be located in europe-west1.

This works:

const {onDocumentCreated} = require("firebase-functions/v2/firestore");
exports.myFunc = onDocumentCreated("/stories/{documentId}", (event) => {...});

This doesn't work:

const {functions} = require("firebase-functions");
exports.myFunc = functions.region("europe-west1").onDocumentCreated("/stories/{documentId}", (event) => {...});

Deploy error:

'onDocumentCreated' is assigned a value but never used no-unused-vars

英文:

I'm using Node.js for my Firebase Functions. Please look at my func below. I want to set this func to be located in europe-west1.

This works:

const {onDocumentCreated} = require("firebase-functions/v2/firestore");
exports.myFunc = onDocumentCreated("/stories/{documentId}", (event) => {…});

This doesn't work:

const {functions} = require("firebase-functions");
exports.myFunc = functions.region("europe-west1").onDocumentCreated("/stories/{documentId}", (event) => {…});

Deploy error:

> 'onDocumentCreated' is assigned a value but never used no-unused-vars

答案1

得分: 4

根据Firebase Functions v2的API参考,您将其作为第一个参数传递(在DocumentOptions对象内,该对象扩展了GlobalOptions对象):

const onDocumentCreated(
  {
    region: 'europe-west1',
    document: '/stories/{documentId}'
  }, 
  (event) => {

  }
);
英文:

As per the API reference for Firebase Functions v2, you pass it in as the first argument (inside the DocumentOptions object, which extends the GlobalOptions object):

const onDocumentCreated(
  {
    region: 'europe-west1',
    document: '/stories/{documentId}'
  }, 
  (event) => {

  }
);

huangapple
  • 本文由 发表于 2023年6月12日 20:18:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76456607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定