Created
January 2, 2012 06:49
-
-
Save lancefisher/1549634 to your computer and use it in GitHub Desktop.
Node.js Code for Twilio Rube Goldberg Contest
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 qs = require('querystring'); | |
http.createServer(function (req, res) { | |
if (req.method === 'POST') { | |
var body = ''; | |
req.on('data', function(data) { | |
body += data; | |
}); | |
req.on('end', function() { | |
var post = qs.parse(body); | |
console.log('POST params:') | |
console.log(post); | |
//set the nixie tubes by sending a request to the netduino | |
var options = { | |
host: 'XXX.XXX.XXXX.XXX', //IP Address to my cable modem | |
port: 8888, | |
path: '/numbers/' + post.Body, | |
}; | |
console.log('sending GET to netduino'); | |
console.log(options); | |
http.get(options, function(netduinoRes) { | |
console.log('response from netduino: ' + netduinoRes.statusCode); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('Happy New Year! We set the nixie tubes!') | |
res.end(); | |
}); | |
}); | |
return; | |
} | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('{ "ok": true }') | |
res.end(); | |
return; | |
}).listen(8080); | |
console.log('server started on port 8080'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment