Skip to content

Instantly share code, notes, and snippets.

@bmabir17
Created April 17, 2020 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmabir17/5e8488558936570cebfaf7785497a08b to your computer and use it in GitHub Desktop.
Save bmabir17/5e8488558936570cebfaf7785497a08b to your computer and use it in GitHub Desktop.
Firebase cloud function for firestore
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