Tag: firebase

如何从Firebasefunction访问Firebase托pipe文件

我有一个简单的firebase函数,它必须发送一个文件来响应文件在/app/one.html中的请求 我的项目目录结构 blog |____app |____index.html |____one.html |____functions |____index.js 我必须访问one.html并从senFile()发送它 index.js const functions = require('firebase-functions'); exports.blog = functions.https.onRequest((req, res) => { res.status(200).sendFile('app/one.html'); #here I need something to do });

当某个键是特定值时运行firebase云端function

const functions = require('firebase-functions'); var IAPVerifier = require('iap_verifier'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.verifyReceipt = functions.database.ref('/Customers/{uid}/updateReceipt') .onWrite(event => { const uid = event.params.uid; var receipt = event.data.val(); (strReceipt).toString('base64'); var client = new IAPVerifier('IAP_secretkey') client.verifyAutoRenewReceipt(receipt, true,function(valid, msg, data){ console.log(' RECEIPT'); if(valid) { console.log('VALID RECEIPT'); console.log('msg:' + msg); var strData = JSON.stringify(data); console.log('data"' + strData); const newReceiptRef […]

Firebase云function路由

如何在HTTP中处理类似/ user /:id和/ user /:id / report的path触发Firebase云function,并访问参数ID? 我不喜欢下一个解决scheme,因为我所有的函数都是前缀/ api的一部分 : const app = require('express')(); exports.api= functions.https.onRequest(app); app.get('/user/:uid/report', (req, res) => {}): 但是我需要这样的东西: exports['/user/:uid/report'] = functions.https.onRequest((req, res) => { // … });

推入Firebase数据库时如何设置按键?

当我从前端(Angular 4)和后端(Firebase函数)向Firebase数据库写入数据时,Firebase会生成一个按键。 使用这个密钥,我将来无法访问数据,因为密钥是唯一的。 我想知道是我可以自己设置密钥的任何方式,或者我可以在不知道密钥的情况下访问数据? 这是我从前端的代码: this.db.list(`${this.basePath}/`).push(upload); 这是我的后端代码: admin.database().ref('/messages').push({original: original}).then(function (snapshot) { res.redirect(303, snapshot.ref);}); 我推送的所有数据将在path / pushID / data下 在不知道pushID的情况下,我无法访问数据。 我想要的最好的情况是path/我自己的pushID /数据 非常感谢您的帮助!

使用.limit()和Firestore查询

我有一个使用Firestore作为队列的应用程序。 数据来自另一个来源,存储在Firestore的/data/{id} , unprocessed的属性设置为true。 在我的Node.js脚本中,我想要一次查询这些未处理的logging,以缓慢地处理它们。 有成千上万的logging,所以试图将它们全部加载到内存中会使进程崩溃。 码: firestore.collection('data').where('unprocessed', '==', true).limit(25).onSnapshot((snapshot) => { snapshot.forEach((doc) => { processItem(doc); }); }); processItem()函数执行必要的处理,将数据保存回Firestore, unprocessed属性设置为false。 我正在运行的问题是,任何时候我试图运行这个代码,我得到以下错误: Error: Error 3: Order must include __name__ at sendError (C:\[myApp]\node_modules\@google-cloud\firestore\src\watch.js:254:15) at DestroyableTransform.stream.on.proto (C:\[myApp]\node_modules\@google-cloud\firestore\src\watch.js:532:13) at emitOne (events.js:115:13) at DestroyableTransform.emit (events.js:210:7) at addChunk (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:284:12) at readableAddChunk (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:271:11) at DestroyableTransform.Readable.push (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:238:10) at DestroyableTransform.Transform.push (C:\[myApp]\node_modules\readable-stream\lib\_stream_transform.js:146:32) at afterTransform (C:\[myApp]\node_modules\readable-stream\lib\_stream_transform.js:102:51) […]

从嵌套字典中创build一个数组

我试图从DataSnapshot中提取嵌套字典。 var query = admin.database().ref("meetings").orderByChild("deadline"); query.once("value").then((snapshot) => { snapshot.forEach((child) => { console.log(snapshot.val()); } } 这段代码打印这个: { '82BE0F33-6812-4EFF-8CB4-FABDACA2B329': { deadline: 1509634558, name: 'cfedfgh', users: { '8YUDtUJuIde8fLaHCfeuSNsHUyq2': '1', DVAYNspxcGfB001RSkq3S8cxvsH3: '1', fJXgRJBoFAU0SmA2Zhn4DpdyLGh1: '1' } } } 我将如何去创build一个字典用户值的数组? 或者访问它们。 做console.log(child.child("users").val()); 给我一个null 。 数据库结构:

从subprocess执行node.js中的代码

新的node.js我试图从一个模块的subprocess中执行一些代码。 让我解释一下,我有我的简单的服务器在index.js var server = http.createServer(handleRequest); server.listen(PORT, function(){ console.log("Server listening on: http://localhost:%s", PORT); }); 当一个URL被提取时,我启动一个subprocess: function handleRequest(req, res){ console.log('Request path = ' + req.url) launchWorker(req.url) res.end('Path Hit: ' + req.url); } // workers execution function launchWorker(path) { const worker = child_process.spawn('node', ['./worker.js', path.substring(1)]) worker.stdout.on('data', function(data) { console.log('worker: ' + data.toString()) }); worker.stderr.on('data', function(data) { console.log('stderr […]

FCM – node.js中的定时器function

这就是我正在做一个Firebase云function发送静默推送通知: exports.sendSilentPyngNotification = functions.database.ref('/SNotification/{userid}').onWrite(event => { const userid = event.params.userid console.log('Start sending SILENT Notificaitons:-'); // Get the list of device notification tokens for the respective user const getDeviceTokensPromise = admin.database().ref(`/personal/${userid}/notificationTokens`).once('value'); // Get the user profile. const getUserProfilePromise = admin.auth().getUser(userid); return Promise.all([getDeviceTokensPromise, getUserProfilePromise]).then(results => { const tokensSnapshot = results[0]; const user = results[1]; // Check if […]

将Firebases的thirdpartyuserdata对象发布到服务器

我正在使用Firebase和SimpleLogin来允许用户通过Google,Twitter等login 我想使用一些thirdpartyuserdata对象来创build我的应用程序在Node上运行的用户configuration文件。 目前我发布这个数据到服务器,以便我可以添加到它并创buildconfiguration文件对象,但我想知道是否有一个更好的方式做到这一点 – 有什么我可以调用服务器端获得这thirdpartyuserdata而不必从客户端发布?

处理Firebase中的多个url以供参考?

我有一个情况,有多个用户,他们都有独特的hashId分配给他们,这使得他们的URL不同。 users/hashId/bla/blah 这些URL唯一的区别是hashId值。 当我的客户端更新firebase中的数据时,我需要将服务器交互应用到节点端的child_added事件侦听器。 应用程序可以有任何数量的用户,如何缩放每个URL的child_added? 有没有dynamicUrl的概念? 由于每个URL的引用都是新的,我不确定这种情况。 另外我不希望去一个for循环,dynamic事件绑定。 PS:Firebase比较新。