Setting up Cloud Functions
firebase.json
https://github.com/stevekinney/hot-takes-redux/blob/live-coding/firebase.json
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "build",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
functions/package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "^4.1.2",
"firebase-functions": "^0.5"
},
"private": true
}
// **** functions/index.js ****
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.shushYellers = functions.database.ref('/messages/{message}/content').onWrite(event => {
const data = event.data;
const content = data.val();
if (content && content === content.toUpperCase()) {
data.ref.set(content.toLowerCase());
}
});