Tag: function

Firebase .on('value')代码块不在内部执行云function。 任何build议要解决?

我发现它真的很奇怪,当我把它放在一个.html文件中时,它会执行相同的代码,并检查控制台日志是否正常,但是当我将完全相同的代码块放入一个不执行的云function中由于某种原因正在被跳过。 我需要做的是从configuration对象获取一些configuration参数,并根据需要使用它们。 var db = admin.database().ref(); var configRef = db.child("config"); configRef.on('value', function(snap){ var snapvalue = snap.val(); var totalLength = Object.keys(snapvalue).length; $.each( snapvalue, function( key, value ) { console.log(value,key); }); }); 完成的云function如下所示: exports.myFunction = functions.database.ref('/object/{list}').onWrite(event =>{ console.log("Inside myFunction…"); var db = admin.database().ref(); var configRef = db.child("config"); configRef.on('value', function(snap){ var snapvalue = snap.val(); $.each( snapvalue, function( key, […]

从谷歌存储的Firebase下载云function

我有一个在firebase中的集合,看起来像这样: people: -KuM2GgA5JdH0Inem6lGaddclose appliedTo: "-KuM1IB5TisBtc34y2Bb" document: "docs/837c2500-9cbe-11e7-8ac1-17a6c37e2057" name: "Test Testerson" 文档节点包含存储桶中文件的path。 是否有可能使用http的firebase函数将这个文件下载到客户端。 根据节点/stream向客户端的Stream文件,我应该能够stream式地快速响应。 谷歌存储readstream会为此工作? 谢谢, 本

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) => { // … });

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 […]

Node.js“on”函数 – 它有什么作用?

var rd = readline.createInterface({ input: fs.createReadStream(file), output: process.stdout, terminal: false }); rd.on('line', function(line) { 任何方式如何使“开”工作同步。 再次执行循环之前,需要在“on”循环内执行代码。 有什么办法如何做到这一点?

从两个来源rx.js追赶订阅

我需要结合追赶和订阅新的饲料。 所以,首先我要查询数据库中所有我错过的新logging,然后切换到所有正在进入的新logging的pub sub。 第一部分很容易做你的查询,也许在500批次,这将给你一个数组,你可以rx.observeFrom。 第二部分很简单,你只需要在pubsub上放一个rx.observe。 但我需要按顺序进行,所以在我开始播放新歌曲之前,我需要播放所有的旧唱片。 我想我可以开始订阅pubsub,把这些放在一个数组中,然后开始处理旧的数据,当我完成后,删除dups(或者因为我做了dup检查)允许less数dups,但是播放积累的logging,直到他们走了,然后一个一个出来。 我的问题是做这件事的最好方法是什么? 我应该创build一个订阅,开始build立一个数组中的新logging,然后开始处理旧的,然后在oldrecord过程的“然后”订阅另一个数组? 好吧,这是我迄今为止。 我需要build立testing,并完成一些psudo代码,以确定它是否工作,更不用说是一个很好的实现。 在我埋葬自己之前,随时可以阻止我。 var catchUpSubscription = function catchUpSubscription(startFrom) { EventEmitter.call(this); var subscription = this.getCurrentEventsSubscription(); // calling map to start subscription and catch in an array. // not sure if this is right var events = rx.Observable.fromEvent(subscription, 'event').map(x=> x); // getPastEvents gets batches of 500 iterates over […]

Firebase的云端函数在Algolia中为Firebase数据库对象build立索引

我通过文档,github仓库,但没有为我工作呢。 我的数据结构: App { posts : { <post_keys> : { auth_name : "name", text : "some text" //and many other fields } } } 1) Github存储库 :如果我使用这个,我只从一个函数获得一个字段,如果我需要所有的字段,我将需要为每个函数编写单独的函数,这是一个坏的方法。 2) Algolia Node.js的官方文档 :这不能作为一个云function部署,但它做我打算做的。 我如何编写一个可以在Firebase上部署的函数,并获取在Algolia中使用其密钥索引的整个对象?

云function“event =>”文档

我对云function很陌生,我认为它们很酷。 我已经search了可以由“event”调用的方法的完整列表以及如何使用它们的文档,但是我没有find任何方法。 在下面的代码事件的例子是用来调用data.current.child等。有人可以帮助我find“事件”下方法的文档。 exports.getPath = functions.database.ref('/Transaction/{id}') .onWrite(event => { // Grab the current value of what was written to the Realtime Database. const trans = event.data.current.child('Request').val();

如何使用简单的HttpGET-CRUD-NodeJS例子?

鉴于我只是使用生成的默认模板: module.exports = function (context, req, intable) { context.log("Retrieved records:", intable); context.res = { status: 200, body: intable }; context.done(); }; 和下面的json文件: { "bindings": [ { "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get" ], "authLevel": "function" }, { "type": "http", "direction": "out", "name": "res" }, { "type": "table", "name": "inTable", "tableName": "person", "connection": […]

我是否需要在每个Cloud Function模块文件的顶部调用admin.initializeApp?

我的firebase的云端函数index.js已经达到我想开始将代码文件拆分成多个模块文件的大小。 不过,是否需要在每个将访问Firebase数据库的模块/文件的顶部调用这一行尚不清楚。 admin.initializeApp(functions.config().firebase); 请原谅,如果这真的很明显。 我不是一个有经验的Node.js用户。