Firebase Functions集成Express遇TypeError: handler is not a function问题
解决方案
问题出在你配置minInstances的方式不对——minInstances属于Firebase Functions的运行时实例配置,不能直接作为functions.https.onRequest()的第一个参数传入。
正确的写法是通过functions.runWith()来指定运行时选项,再链式调用https.onRequest():
exports.myFunction = functions.runWith({ minInstances: 2 }).https.onRequest(app);
错误原因
你之前的代码functions.https.onRequest({minInstances: 2}, app)里,第一个参数被onRequest方法当成了请求处理函数(handler),但你传入的是一个配置对象,不是函数,所以才会抛出TypeError: handler is not a function。
functions.https.onRequest()的第一个参数如果是对象,它接受的是HTTP请求级别的配置(比如跨域规则cors),而非实例数量这类运行时配置。运行时配置必须通过runWith()方法来设置。
内容的提问来源于stack exchange,提问作者ChopperOnDick
相关产品推荐
相关产品推荐

