Forked from sharon-rozinsky/firebase-by-example-cloud-functions.js
Created
October 8, 2018 01:41
-
-
Save spac3unit/61a3a3970c20df1af94ce3c270c87f5f to your computer and use it in GitHub Desktop.
firebase-by-example: Cloud Functions
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
| // 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