Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save spac3unit/61a3a3970c20df1af94ce3c270c87f5f to your computer and use it in GitHub Desktop.

Select an option

Save spac3unit/61a3a3970c20df1af94ce3c270c87f5f to your computer and use it in GitHub Desktop.
firebase-by-example: Cloud Functions
// This is the index.js file in which we write our cloud functions
const https = require('https');
const functions = require('firebase-functions');
// Function that listens to a firestore events
exports.messageSniffer = functions.firestore
.document('forms/{userName}')
.onCreate(event => {
var dataWritten = event.data.data();
console.log(dataWritten);
if(dataWritten.name == 'firebaseUser') {
return event.data.ref.update({"message" : "This message was updated by the messageSniffer cloud function"});
}
});
// Function that listens to HTTP requests
exports.echoMessage = functions.https.onRequest((request, response) => {
var receivedText = request.query.text;
if(receivedText != null) {
response.send("Got a message to echo: " + receivedText);
} else {
response.send("No text to echo was received");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment