2017-09-13 105 views
2

您好我想從firebase數據庫中使用firebase雲功能http觸發器獲取數據。是否有可能使用functions.database.ref?如何使用firebase雲功能從firebase數據庫獲取數據http觸發器

var functions = require('firebase-functions'); 
var cors = require("cors"); 
var express = require('express'); 
var http = require('http'); 

const app = express() 
//~ app.use(cors({ origin: true })) 
app.get("/", (request, response) => { 
    response.send("Hello from Express on Firebase with CORS!") 
}) 
app.get("/:id", (request, response) => { 
    functions.database.ref('/Users/'+request.params.id) 
}) 

    exports.httpFunction = functions.https.onRequest(app); 

感謝

+1

你提的問題是過於寬泛。如果你嘗試了某些東西,請添加一些代碼如果您沒有請Google搜索並閱讀一些關於Firebase和雲功能的教程。 Firebase doc對於解釋事物非常有用。檢查[問]以瞭解優秀問題。 – bennygenel

+0

請檢查我的代碼 – harry

回答

2

您可以使用Firebase Admin SDK使雲功能數據庫裏面操作。

而不是使用

functions.database.ref() 

您可以使用

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

// inside your triggered function 
admin.database().ref('path/to/your/ref').on('value').then((snapshot) => { ... }) 
+0

獲取內部服務器錯誤 – harry

+0

@harry請更新您的問題,並說明您完成的操作和完成的錯誤。 – bennygenel

+0

感謝@bennygenel它的作品。 – harry

相關問題