我正試圖在Cloud代碼中實現一個簡單的SSE。服務器在Cloud代碼中發送事件
這裏是我的快遞路線打開連接:
app.get('/call', function(req, res) {
// let request last as long as possible
req.socket.setTimeout(30000);
//send headers for event-stream connection
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
res.write('\n');
// The 'close' event is fired when a user closes their browser window.
req.on("close", function() {
});
});
我也確信包括:
var http = require('http');
問題是,我得到這個錯誤:
I2014-06-28T19:09:50.500Z] TypeError: Object function() {
throw Error('IncomingMessage.socket not supported');
} has no method 'setTimeout'
at app.js:129:14
at callbacks (express_router.js:161:37)
at param (express_router.js:135:11)
at pass (express_router.js:142:5)
at Router._dispatch (express_router.js:170:5)
at Object.router (express_router.js:33:10)
at next (connect_proto.js:240:15)
at Object.handle (app.js:88:7)
at next (connect_proto.js:240:15)
at Object.parseExpressCookieSession [as handle] (parse-express-cookie-session.js:315:7)
我也嘗試了:
req.setTimeout(30000);
但是得到一個類似的錯誤。
我看了一些關於如何setTimeout
沒有實現,直到節點的更高版本。這可能是問題嗎?我無法找到Parse正在運行的節點的版本。
'process.versions' – Prinzhorn