在本地部署或运行​​功能(HTTP功能+实时数据库功能)

时间:2018-07-12 15:25:39

标签: javascript firebase google-cloud-functions

如何同时运行HTTP函数和实时数据库函数

我在这里的文档中看到:Run functions locally如何通过以下命令运行HTTP函数:firebase serve,对于实时数据库功能如何运行:firebase functions:shell,但这对我不起作用

同样,当我使用命令firebase deploy --only functions部署功能时,它也仅部署了HTTP功能。

我的方法有什么问题?

结构:

/functions
|--index.js
|--saveDetectedBeacons.js
|--generatePresence.js
|--package.json

index.js:

const functions = require('firebase-functions');
const admin = require("firebase-admin");
const saveDetectedBeaconsFunc = require('./saveDetectedBeacons');
const generatePresenceFunc = require('./generatePresence');
const serviceAccount = require("./serviceAccountKey");
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://exampleDb.firebase.com"
});
const db = admin.database();
exports.saveDetectedBeaconsApi = functions.https.onRequest((request, response) => {
    saveDetectedBeaconsFunc.handler(request,response,db)
});
exports.generatePresenceApi = functions.database.ref('/reports').onCreate((snapshot, context) => {
    generatePresenceFunc.handler(snapshot, context, db)
});

saveDetectedBeacons.js:

exports.handler = function (request, response, db) {
    // do something 
};

generatePresence.js

exports.handler = function (snapshot, context, db) {
     // do something 
};

0 个答案:

没有答案