有可能有一种全局变量关于 firebase 云功能?
我的意思是我可以有一个index.js就像设置全局变量一样,比方说panicModeVariable
.
我想在执行任何操作之前检查我的云函数中的此变量,例如在 auth create user 触发器中。
const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var globalVariable = false;
// Create Account User
exports.createUserAccount = functions.auth.user().onCreate(event => {
if (!globalVariable) {
const uid = event.data.uid
const email = event.data.email
const photoUrl = event.data.photoURL
}
[...]
我尝试使用两个虚拟函数
exports.setGlobal = functions.https.onRequest((request, response) => {
globalVariable = true;
response.send("Set " + globalVariable);
});
exports.getGlobal = functions.https.onRequest((request, response) => {
response.send("Read " + globalVariable);
});
但似乎我无法按照我想要的方式访问这个变量。
写入函数使用“局部”变量,而读取函数始终使用初始值。
如果可能的话,我想这样做,拥有一种服务器端变量直接读取,无需调用 SDK 来读取数据库存储的值(这样就没有函数调用计数)。
您可以使用环境配置变量https://firebase.google.com/docs/functions/config-env https://firebase.google.com/docs/functions/config-env
据我所知,您无法在函数本身中设置它们,需要在上传函数之前通过 CLI 设置它们。
你可以做类似的事情firebase functions:config:set panic.mode=true
然后在你的createUserAccount
你可以调用的函数functions.config().panic.mode
但这对你没有帮助set
变量通过https
扳机。为此,您需要使用数据库。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)