为什么 firebase serve 不工作但 firebase deploy 工作正常?
Why firebase serve is not working but firebase deploy is working fine?
每当我使用 firebase deploy 时,它都会成功创建数据,但每当我使用 firebase serve 时,它就会进入 catch 函数!
我使用的函数是:
exports.createUser = functions.https.onRequest((req, res) => {
const newUser = {
body: req.body.body,
userName: req.body.userName,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
};
admin
.firestore().collection('screems').add(newUser)
.then(doc => {
return res.json({
message: `document ${doc.id} created successfully`
});
})
.catch(err => {
res.status(500).json({
error: 'something went wrong'
});
console.error(err);
});
});
我用邮递员检查 API 但它总是说 “出了点问题”;
如有关 running functions locally 的文档中所述。
If you have Cloud Functions that use the Firebase Admin SDK to write
to Cloud Firestore, these writes will be sent to the Cloud Firestore
emulator if it is running. If further Cloud Functions are triggered by
those writes, they will be run in the Cloud Functions emulator.
部署的函数连接到您的实际 Cloud Firestore 实例,但是当您在本地 运行 您的函数时,您需要 install, configure, and integrate the emulators 您的 Cloud Function 应该使用。
每当我使用 firebase deploy 时,它都会成功创建数据,但每当我使用 firebase serve 时,它就会进入 catch 函数! 我使用的函数是:
exports.createUser = functions.https.onRequest((req, res) => {
const newUser = {
body: req.body.body,
userName: req.body.userName,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
};
admin
.firestore().collection('screems').add(newUser)
.then(doc => {
return res.json({
message: `document ${doc.id} created successfully`
});
})
.catch(err => {
res.status(500).json({
error: 'something went wrong'
});
console.error(err);
});
});
我用邮递员检查 API 但它总是说 “出了点问题”;
如有关 running functions locally 的文档中所述。
If you have Cloud Functions that use the Firebase Admin SDK to write to Cloud Firestore, these writes will be sent to the Cloud Firestore emulator if it is running. If further Cloud Functions are triggered by those writes, they will be run in the Cloud Functions emulator.
部署的函数连接到您的实际 Cloud Firestore 实例,但是当您在本地 运行 您的函数时,您需要 install, configure, and integrate the emulators 您的 Cloud Function 应该使用。