I can't access the SSE page(http://sse.abo.ink/sse) on my Node.js website.
When running on my local machine, it works fine:
My code(simplified version):
const http = require('http');
var server = http.createServer(function(req, res) {
var path = (new URL(`http://localhost:3000${req.url}`).pathname);
if (path == '/') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<h1>200 OK</h1>');
res.end(`\n`);
} else if (path == '/sse') {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
setInterval(function() {
res.write('data: SSE server is OK.\n\n');
}, 1000);
} else {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.write('<h1>404 Not Found</h1>');
res.end(`\n`);
}
});
server.listen(3000);