Skip to content

Instantly share code, notes, and snippets.

@millerdrew
Created July 25, 2018 10:09
Show Gist options
  • Save millerdrew/7271b30417106c1b4f820553f2e7fc04 to your computer and use it in GitHub Desktop.
Save millerdrew/7271b30417106c1b4f820553f2e7fc04 to your computer and use it in GitHub Desktop.
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();
// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addVocab = functions.https.onRequest((req, res) => {
// Grab the text parameter.
const word = req.query.word;
const meaning = req.query.meaning;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
return admin.database().ref('/japanese').push({word: word, meaning: meaning}).then((snapshot) => {
// Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
return res.redirect(303, snapshot.ref.toString());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment