added global firebase context settings
This commit is contained in:
@ -11,6 +11,15 @@ This means that the nodes can run outside of the normal security rules, in admin
|
||||
The configuration needs two parameters, the first is the text of the service account credentials private key file. This can be found by going to the firebase console, then to the cogwheel icon at the top left then to project settings and then "Service Accounts". Click "Generate new private key)".
|
||||
The second parameter is the database url for the database, and th url has the format of "https://myprojectname.firebaseio.com" and can also be fpund in the above place in the firebase console.
|
||||
|
||||
After initializing, the reference to the firebase SDK is stored in the global context variable 'firebase', which can be used
|
||||
in any function like this;
|
||||
|
||||
let fb = global.get('firebase')
|
||||
fb.firestore().doc('foo/bar').get().then((ref)=>{
|
||||
let d = ref.data()
|
||||
node.send( {payload: {data: d}});
|
||||
})
|
||||
|
||||
# Realtime Database (rtdb) Nodes
|
||||
|
||||
## rtdb-get
|
||||
|
||||
@ -28,6 +28,8 @@ module.exports = function(RED) {
|
||||
credential: credobj,
|
||||
databaseURL: this.dburl
|
||||
});
|
||||
let global = this.context().global
|
||||
global.set('firebase', _admin)
|
||||
console.log('setting storage....')
|
||||
|
||||
s = new Storage({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-contrib-firebase-admin",
|
||||
"version": "1.0.65",
|
||||
"version": "1.0.7",
|
||||
"description": "A node-red module that wraps the server-side admin SDK of firebase, firestore, et.c.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -26,29 +26,14 @@ module.exports = function(RED) {
|
||||
let path = msg.payload.path || this.path
|
||||
let bucket = msg.payload.bucket || this.bucket
|
||||
console.log('storage-read reading from bucket "'+bucket+'" path "'+path+'"')
|
||||
|
||||
this.storage.getBuckets().then((results)=>{
|
||||
const [buckets] = results;
|
||||
|
||||
console.log('Buckets:');
|
||||
buckets.forEach(bucket => {
|
||||
console.log(bucket.name);
|
||||
});
|
||||
|
||||
|
||||
this.storage
|
||||
.bucket(bucket)
|
||||
.file(path).download().then((file)=>{
|
||||
console.log('storage-read got file')
|
||||
//console.dir(file)
|
||||
node.send({payload:file})
|
||||
|
||||
})
|
||||
|
||||
this.storage
|
||||
.bucket(bucket)
|
||||
.file(path).download().then((file)=>{
|
||||
console.log('storage-read got file')
|
||||
//console.dir(file)
|
||||
node.send({payload:file})
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user