Created
April 17, 2020 21:29
-
-
Save bmabir17/5e8488558936570cebfaf7785497a08b to your computer and use it in GitHub Desktop.
Firebase cloud function for firestore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
// var serviceAccount = require("/home/bmabir/dev/tran-dao-8e837f43806d.json"); | |
admin.initializeApp({ | |
credential: admin.credential.applicationDefault() | |
}); | |
const db = admin.firestore(); | |
// // Create and Deploy Your First Cloud Functions | |
// // https://firebase.google.com/docs/functions/write-firebase-functions | |
// | |
exports.helloWorld = functions.https.onRequest((request, response) => { | |
response.send("Hello from tran dao server!"); | |
}); | |
exports.get_relief = functions.https.onRequest((request, response) => { | |
const docRef = db.collection('relief'); | |
docRef.get() | |
.then(snapshot => { | |
let arrayR = snapshot.docs.map(doc => { | |
return doc.data(); | |
}); | |
return response.json(arrayR); | |
}).catch(err => { | |
console.log('Error getting document', err); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment