Cannot get SSE events to file in browser.
This the server code (express):
app.all('/callme', function(req, res){
res.writeHead(200, {
'Connection': 'keep-alive',
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache'
});
setInterval(function(){
console.log('writing');
res.write((new Date()).toString() + '\n');
}, 1000);
})
This the client code:
var source = new EventSource('/events');
source.onmessage = function(e) {
document.body.innerHTML += e.data + '<br>';
};
I use this same server code using XHR on the client and it works. The server appears to be sending the data correctly, but not getting fired in the browser..
I've already read JavaScript EventSource SSE not firing in browser Doesn't seem to apply here, as I'm not running anti-virus that would affect it.