有可能有一种
全局变量
关于firebase云功能?
我是说我可以
指数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来读取数据库存储值
(这样就不会有函数调用计数)。