Created
September 9, 2011 23:04
-
-
Save tsabat/1207552 to your computer and use it in GitHub Desktop.
node server
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
var http = require("http"); | |
var redis = require("redis"); | |
var url = require('url'); | |
client = redis.createClient(); | |
var requests = []; | |
var strings = []; | |
http.createServer( | |
function(request, response) { | |
if (request.url === '/favicon.ico') { | |
response.writeHead(200, {'Content-Type': 'image/x-icon'}); | |
response.end(); | |
console.log('favicon requested'); | |
} else { | |
requests.push([request, response]); | |
//console.log(requests.length) | |
} | |
}).listen(8000); | |
function foo() { | |
var d = new Date(); | |
var key = "pink-eye-p-" + d.getMinutes(); | |
//console.log('reading key into array from ' + key); | |
client.smembers(key, function(err, obj) { | |
if (obj) { | |
for (var i = 0; i < obj.length; i++) { | |
strings.push(JSON.parse(obj[i])); | |
} | |
} | |
}); | |
}; | |
var myloop = function() { | |
while (requests.length) { | |
//console.log('sending requests back.'); | |
out = requests.pop(); | |
out[1].writeHead(200, { "Content-Type": "application/json" }); | |
//var lVars = url.parse(out[0].url, true); | |
//var wrap = lVars.query.callback; | |
//var s = wrap+'({"coordinates":'+JSON.stringify(strings)+'})'; | |
out[1].end('{ length:' + requests.length + '}'); | |
} | |
strings = []; | |
} | |
setInterval(myloop, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment