-
-
Save rotolonico/0e12c764c25e058b3bc75156cbe66b65 to your computer and use it in GitHub Desktop.
This file contains 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'); | |
admin.initializeApp(functions.config().firebase); | |
var database = admin.database(); | |
exports.helloWorld = functions.https.onRequest((request, response) => { | |
response.send("Hello from Firebase!"); | |
}); | |
exports.textToLength = functions.https.onRequest((request, response) => { | |
var text = request.query.text; | |
var textLength = text.length; | |
response.send(String(textLength)); | |
}); | |
exports.newNodeDetected = functions.database.ref('users/{userId}/Name') | |
.onWrite((change, context) => { | |
var oldName = change.before.val(); | |
var newName = change.after.val(); | |
var userId = context.params.userId; | |
database.ref('metadata/lastChangedName/').set(userId + " changed his name from " + oldName + " to " + newName); | |
return null; | |
}); | |
exports.pushDataEveryMinute = functions.pubsub.schedule('every 1 minutes').onRun((context) => { | |
var date = new Date(); | |
database.ref("metadata/lastUpdate/").set(date.getTime()); | |
return null; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment