Javascript 错误:使用firebase云函数时超过了截止日期
我编写了一个小的联系表单,它调用firebase cloud函数将请求存储到cloud firestore。一切正常,但60秒后网站会抛出以下错误:Javascript 错误:使用firebase云函数时超过了截止日期,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我编写了一个小的联系表单,它调用firebase cloud函数将请求存储到cloud firestore。一切正常,但60秒后网站会抛出以下错误: 错误:超过截止日期 我使用了这个参考: 这是我的云功能: exports.newRequest = functions.https.onCall((data, context) => { return admin .firestore() .collection("requests") .add(data)
错误:超过截止日期
我使用了这个参考:
这是我的云功能:
exports.newRequest = functions.https.onCall((data, context) => {
return admin
.firestore()
.collection("requests")
.add(data)
.then(ref => {
console.log(`New request written. ${ref}`)
return ref.id
})
.catch(err => {
throw new functions.https.HttpsError("unknown", error.message, error)
})
})
这是函数调用:
const functions = firebase.functions()
const addMessage = functions.httpsCallable(`newRequest`)
addMessage({
name: name,
contact: contact,
message: message,
timestamp: new Date(Date.now()).toLocaleString(),
})
.then(result => {
console.log(`Cloud function called successfully. Ref: ${result.data}`)
})
.catch(error => {
// Getting the Error details.
var code = error.code
var message = error.message
var details = error.details
console.log(code, message, details)
})
有人知道怎么解决这个问题吗
编辑:
以下是云功能日志:
7:19:33.751 PM newRequest Function execution started
7:19:33.751 PM newRequest Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:19:33.755 PM newRequest Function execution took 5 ms, finished with status code: 204
7:19:33.896 PM newRequest Function execution started
7:19:33.896 PM newRequest Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:19:34.744 PM newRequest New request written. [object Object]
7:19:34.746 PM newRequest Function execution took 851 ms, finished with status code: 200
我的详细设置:
- 我有一个盖茨比页面,我在firebase
- 我使用以下handleSubmit方法获得了一个contact form react组件李>
Exception: Error: deadline-exceeded at new HttpsErrorImpl (http://localhost:8000/commons.js:4409:28) at http://localhost:8000/commons.js:4715:20
code: "deadline-exceeded"
details: undefined
message: "deadline-exceeded"
stack: "Error: deadline-exceeded↵ at new HttpsErrorImpl (http://localhost:8000/commons.js:4409:28)↵ at http://localhost:8000/commons.js:4715:20"
__proto__: Error
这就是承诺的创造者:
/**
* Returns a Promise that will be rejected after the given duration.
* The error will be of type HttpsErrorImpl.
*
* @param millis Number of milliseconds to wait before rejecting.
*/
function failAfter(millis) {
return new Promise(function (_, reject) {
setTimeout(function () {
reject(new HttpsErrorImpl('deadline-exceeded', 'deadline-exceeded'));
}, millis);
});
}
我从几天以来就遇到了这个问题,我不知道它是从哪里来的:(这是React Hooks的“useEffect”吗
如果是,则每次渲染都会执行firebase初始化(在useEffect中)
如果希望useffect只应用一次(如componentDidMount),那么应该在第二个参数中传递一个空数组
useEffect(() => {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig)
} else {
console.log(firebase.apps)
}
}, []);
它是来自React钩子的“useffect”吗
如果是,则每次渲染都会执行firebase初始化(在useEffect中)
如果希望useffect只应用一次(如componentDidMount),那么应该在第二个参数中传递一个空数组
useEffect(() => {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig)
} else {
console.log(firebase.apps)
}
}, []);
错误消息表明您对函数的调用在客户端超时。您必须提供有关函数和客户端观察到的内容的更多信息。嘿,道格!非常感谢您的回答。爱您youtube上的firebase视频。:D我编辑了我的问题。也许这会有所帮助。我不明白what
failAfter
是或您如何使用它。failAfter
是我安装的firebase函数包(@firebase/functions/dist/index.cjs,)中的一种方法。我不使用它。但它似乎产生了承诺。我使用这个firebase版本:“firebase”:“^6.3.1”,“firebase管理”:“^8.3.0”,“firebase函数”:“^3.1.0”
是的,这就是导致您超时的原因。网络连接出现问题,但我不知道是什么问题。错误消息表明您对函数的调用在客户端超时。您必须提供更多有关您在函数和客户端观察到的情况的信息。嘿,道格!谢谢y非常感谢你的回复。爱你youtube上的firebase视频。:D我编辑了我的问题。也许这会有所帮助。我不明白什么是failAfter
,或者你是如何使用它的。failAfter
是我安装的firebase功能包(@firebase/functions/dist/index.cjs)中的一种方法。我不使用它。但它似乎产生了承诺。我使用这个firebase版本:“firebase”:“^6.3.1”,“firebase admin”:“^8.3.0”,“firebase函数”:“^3.1.0”
。是的,这就是导致您超时的原因。网络连接有问题,但我不知道是什么问题。
useEffect(() => {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig)
} else {
console.log(firebase.apps)
}
}, []);