Added functions Helloworld and getUsername for testing

This commit is contained in:
Leon Liang
2019-09-12 16:23:45 -04:00
parent d0b32835ac
commit c716d47254
4 changed files with 412 additions and 5 deletions

View File

@@ -1,8 +1,22 @@
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// // 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 Firebase!");
// });
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
exports.getUsername = functions.https.onRequest((req, res) => {
admin.firestore().collection('users').get()
.then(data => {
let users = [];
data.forEach(doc => {
users.push(doc.data());
})
return res.json(users);
})
.catch((err) => console.error(err));
})