英文:
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) => {
}
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论