0

我想运行一个查询实时数据库在firebase https功能,但它不工作。这里是我的代码在firebase https功能查询不起作用

exports.fetchPost = functions.https.onRequest((req, res) => { 
    if (req.method === 'PUT' || req.method === 'GET') { 
    res.status(403).send('Forbidden!') 
    } 
    let postId = JSON.stringify(req.query.postId) || 
    JSON.stringify(req.body.postId) 
    cors(req, res,() => { 
    admin.database().ref('items') 
     .child(postId) 
     .once('value', s => { 
      console.log(s.val(), s) 
      res.status(200).send(s.val()) 
     }) 
     .catch(e => res.status(500).send(e)) 
    }) 
}) 

我检查了日志。 s.val()返回null,而s返回一个不可用的firebase对象。

Firebase function log

另外,我正在上请求下列返回发送

Error response being returned from the request

任何帮助,将不胜感激,谢谢。

回答

0
admin.database().ref('items') 
    .once('value', data => data.forEach(s => { 
     s.key === postId ? console.log('success!') : console.log('not 
     found'); 
    })) 

试试这段只处理firebase的代码。在这里测试和工作,如果它不起作用,你能请你说明你的物品是如何储存的?

+0

好的,会试试这个,谢谢你的回应。我对firebase仍然陌生,现在一直在使用Parse服务器。我打算做的只是获得单个项目。 –

+0

测试过它,没有工作。与以前一样的错误。另外你的代码有错误,你没有指定三元运算符的else部分。所以我用了一个if语句。 –

+0

是的,我完全忘了那里的其他部分,我已经编辑了更清晰的答案,我希望它有帮助。 –