Can you run Google cloud functions through a firebase event without a server?

I will use the elastic search index next to my firebase application so that it can better support full-text search queries and search queries. Thus, I need to synchronize the bomb data with the elastic search index, and all the examples require a server process that listens for firebase events.

eg. https://github.com/firebase/flashlight

However, it would be great if I just had a google cloud function launched by insertion into firebase node. I see that google cloud functions have different triggers: pub sub, storage and direct ... can any of these bridges go to the firebase node event without an intermediate server?

+4
source share
3 answers

I believe Cloud features for Firebase is what you are looking for. Here are some links:

+4
source

firebaser here

We just released Cloud Functions for Firebase . This allows you to run JavaScript functions on Google servers in response to Firebase events (such as database changes, user login, and more).

+12
source

, Google firebase . Firebase , , firebase.

To do this, I had to write javascript as shown below

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/articles/{articleId}')
        .onWrite(event => {

        // Grab the current value of what was written to the Realtime Database.
        var eventSnapshot = event.data;
        var str1 = "Author is ";
        var str = str1.concat(eventSnapshot.child("author").val());
        console.log(str);

        var topic = "android";
        var payload = {
            data: {
                title: eventSnapshot.child("title").val(),
                author: eventSnapshot.child("author").val()
            }
        };

        // Send a message to devices subscribed to the provided topic.
        return admin.messaging().sendToTopic(topic, payload)
            .then(function (response) {
                // See the MessagingTopicResponse reference documentation for the
                // contents of response.
                console.log("Successfully sent message:", response);
            })
            .catch(function (error) {
                console.log("Error sending message:", error);
            });
        });
0
source

Source: https://habr.com/ru/post/1659923/


All Articles