繁体   English   中英

Node.js Firebase 后

[英]Node.js Firebase Post

我在使用 Node.js 时遇到了一些问题,我完全没有经验。 所以我正在尝试编写 post 方法,但它总是返回

出问题了

但我看不出问题出在哪里

这是代码。

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);
    });

还有我的帖子方法来自 postman。

{
    "content": "First test",
    "userHandle": "some user"
}

这是控制台错误:

错误:无法加载默认凭据。 浏览到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 

它的工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM