Created
June 15, 2017 14:49
-
-
Save milingo/4e81ca987a0ac5b07e8023b8f4462c28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer(function (req, res) { | |
if (req.url === '/live') { | |
res.writeHead(200, { | |
'Content-Type': 'text/event-stream', | |
'Cache-Control': 'no-cache', | |
'Connection': 'keep-alive' | |
}); | |
res.write('retry: 5000\n'); | |
const interval = setInterval(() => { | |
res.write('data: ' + new Date() + '\n\n'); | |
}, 1000); | |
req.on('end', () => clearInterval(interval)); | |
return; | |
} | |
// Normal requests | |
return res.end(); | |
}); | |
server.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment