首页 > 解决方案 > How to trigger a service in App Engine on Firebase data change

问题描述

I have created an app engine basic server and connected it for Firebase:

// server.js

// Express packages
const express = require('express');
const app = express();
const path = require(`path`);
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));

// Firebase packages
var firebase = require('firebase');
var firebaseConfig = {...};

var fire = firebase.initializeApp(firebaseConfig);
var ref = firebase.database().ref('test');
ref.on('child_added', readMessage);

function readMessage(data) {
    console.log('data', data)
};

// Route index
app.get('/', (req, res) => {
  res.send('Hello from App Engine!');

});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
    console.log(`Server listening on port ${PORT}...`);
});

My idea was to trigger this service (not sure which route, but I guess it is open?) when a child is added to the node test on Firebase.

To give a bit of background information, I am basically planning to create a peer connection using webrtc and then parse the video on this nodejs server. I use Firebase for signallin by sending the webrtc information to the node test and then the server can read and process this once there is a change.

I do not understand however how to trigger this service when a child is added (thus when I send some meta data to the node test in Firebase). How do I structure my nodejs code to handle this? Or should this be done differently?

标签: node.jsfirebasegoogle-cloud-platformwebrtc

解决方案


使用带有 Firebase 实时数据库触发器的云功能,我们可以使用 http 或 Cloud Tasks 调用应用引擎端点。


推荐阅读