每当我使用命令“ firebase serve”时,提供给我的localhost地址实际上都无法工作。
我收到的错误消息说某些凭证无法加载。根据其他溢出答案,我正在定义功能,管理并正确初始化应用程序。
const functions = require('firebase-functions');
// importing the admin
const admin = require('firebase-admin');
// initializing the application in order to use app
admin.initializeApp();
// setting up express
const express = require('express')
const app = express();
app.post('/scream' ,(req, res) =>{
const newScream ={
// second body is a property of the request
body: req.body.body,
userHandle: req.body.userHandle,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
}
admin.firestore().collection('screams').add(newScream)
.then(doc => {
// string literal for response stating successful addition of the newScream object
res.json({message: `doucument${doc.id} created successfully`})
})
.catch((err)=>{
res.status(500).json({error: 'Something went wrong'})
console.log(err)
})
})
exports.api= functions.https.onRequest(app)
我希望运行“ firebase serve”,获取本地主机地址,然后使用具有json正文的post方法来测试Postman中的路由。我期望路由成功,但是不会加载凭据,因此尝试结束,然后才能将任何内容发布到数据库。