node.js - 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?
解决方案
使用带有 Firebase 实时数据库触发器的云功能,我们可以使用 http 或 Cloud Tasks 调用应用引擎端点。
推荐阅读
- javascript - Vuejs:根据屏幕大小动态设置标签的垂直属性
- r - 如何按多个变量分组以获得 4 个图表,这取决于一个图中的两个分组?
- python - 在控制台中打开时出现错误 403 google 电子表格 gspread
- spring - MongoDB 的 ObjectId 类型格式
- c# - WebRequest.AddRange 没有返回正确的 Content-Length
- vba - VBA PowerPoint 2016 在 .ConvertToShape 之后塑造 BuildFreeform 属性
- google-cloud-platform - 自动回滚到完全托管的 Cloud Run 的上一个工作修订版
- python - 通过多列合并多个数据框,Pandas,Python
- javascript - 在挂载虚拟 DOM 或挂载真实 DOM 后调用 componentDidMount()
- mysql - MySQL 时间戳字段在 API 响应中返回空对象