Last active
February 11, 2020 10:26
-
-
Save jperasmus/7cee6417b800a81fd0bb1d4073933be0 to your computer and use it in GitHub Desktop.
Example using Flamelink with Cloud Firestore in a Firebase Cloud Function
This file contains hidden or 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'); | |
const flamelink = require('flamelink/app'); | |
// Only import the modules that you need (change `cf` to `rtdb` for Realtime DB) | |
require('flamelink/cf/settings'); | |
require('flamelink/cf/content'); | |
require('flamelink/cf/storage'); | |
require('flamelink/cf/navigation'); | |
require('flamelink/cf/users'); | |
const firebaseApp = admin.initializeApp(functions.config().firebase); | |
const app = flamelink({ | |
firebaseApp, | |
dbType: 'cf' // can be `rtdb` for Realtime DB | |
}); | |
exports.addMessage = functions.https.onRequest((req, res) => { | |
return app.content.get({ schemaKey: 'messages' }) | |
.then(messages => { | |
return res.status(200).json({ messages }); | |
}) | |
.catch(error => { | |
// In a production system you probably don't want to send the full `error` object back | |
res.status(500).json({ error }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment