【发布时间】:2017-09-06 20:31:44
【问题描述】:
我在尝试从云功能访问 firebase 实时数据库时遇到了这个奇怪的错误,我想不出更多关于如何修复它的想法。这是我的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createNewGame = functions.https.onRequest((request, response) => {
return admin.database().ref().once('value').then(function (data) {
console.log("BLA");
response.end();
});
});
还有错误:
info: User function triggered, starting execution
info: Execution took 60010 ms, finished with status: 'timeout'
info: Execution took 60046 ms, finished with status: 'crash'
error: Something went wrong with the function!
error: Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:504:11)
at ServerResponse.setHeader (_http_outgoing.js:511:3)
at ServerResponse.header (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\response.js:730:10)
at ServerResponse.send (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\response.js:170:12)
at ServerResponse.json (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\response.js:256:15)
at ProxyServer.Supervisor._proxy.on (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\@google-cloud\functions-emulator\src\supervisor\supervisor.js:104:14)
at ProxyServer.emit (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\eventemitter3\index.js:144:27)
at ClientRequest.proxyError (C:\Users\Thugm\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:156:18)
at emitOne (events.js:115:13)
at ClientRequest.emit (events.js:210:7)
如果有人能指出我找到解决方案的正确方向,我们将不胜感激。干杯!
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions