[英]Node.js Firebase Post
I'm having some problems with Node.js, I have no experience at all.我在使用 Node.js 时遇到了一些问题,我完全没有经验。 So I'm trying to write post method, but it's always returning所以我正在尝试编写 post 方法,但它总是返回
Something went wrong出问题了
but I can't see where is the problem但我看不出问题出在哪里
Here is the code.这是代码。
exports.createNews = functions.https.onRequest((req, res) => {
const newNews = {
content: req.body.content,
userHandle: req.body.userHandle,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
};
admin
.firestore()
.collection('news')
.add(newNews)
.then((doc) => {
res.json({ message: `document ${doc.id} created successfully` });
})
.catch((err) => {
res.status(500).json({ error: 'Something went wrong' });
console.error(err);
});
And my post method from postman.还有我的帖子方法来自 postman。
{
"content": "First test",
"userHandle": "some user"
}
Here is console error:这是控制台错误:
Error: Could not load the default credentials.错误:无法加载默认凭据。 Browse to https://cloud.google.com/docs/authentication/getting-started for more information.浏览到https://cloud.google.com/docs/authentication/getting-started了解更多信息。
at GoogleAuth.getApplicationDefaultAsync (C:\Users\Rade\Desktop\fireshark-back\functions\node_modules\google-auth-library\build\src\auth\googleauth.js:161:19) at process._tickCallback (internal/process/next_tick.js:68:7)
gcloud auth application-default login
did it's job.它的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.