-
-
Save tjbrennan/c089fa18e728a658b290 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Long-polling chat server + client. | |
var chats = []; | |
require('http').createServer(function(req, res) { | |
if (/\/c/.test(req.url)) return res.end(chats.join('\n')); | |
var m = req.url.split('='); | |
if (m.length > 1) chats.unshift(m[1].replace(/\+/g, ' ')); | |
res.end('<html><body><form><input name="m"></form><pre></pre><script>' | |
+ 'var r=new XMLHttpRequest;(function e(){r.open("GET","/c",true);r.send();r.onreadystatechange=function(){if(r.readyState==4){document.getElementsByTagName("pre")[0].innerHTML=r.responseText;setTimeout(e,1e3)}}})();document.forms[0].m.focus()' | |
+ '</script></body></html>') | |
}).listen(parseInt(process.env.PORT, 10)|| 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment