Skip to content

Instantly share code, notes, and snippets.

@tuchida tuchida/app.js
Created Jan 10, 2014

Embed
What would you like to do?
Server-Sent Eventsテスト
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.type('text/html');
res.send('<script>' +
'new EventSource(\'/event/a\').addEventListener(\'message\',function(event) {' +
'document.body.appendChild(document.createElement(\'div\')).textContent = event.data;' +
'});' +
'</script>');
});
app.get('/event/:id', function(req, res) {
res.type('text/event-stream');
setInterval(function() {
// 任意の文字列を返している、という想定
res.write('data: <script>alert(1)</script>\n\n');
}, 1000);
});
app.listen(3000);
{
"name": "sse-test",
"scripts": {
"run": "node app.js"
},
"dependencies": {
"express": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.