Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a more robust you say

  • Loading branch information...
commit f9487193c4df26b05eeb72263c42683f8695a627 1 parent 4ec8f2e
@lyle authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 008b_yousay.js
View
44 008b_yousay.js
@@ -0,0 +1,44 @@
+var http = require('http');
+var url = require('url')
+var qs = require('querystring')
+var exec = require('child_process').exec
+var os = require('os')
+
+var messages = [];
+
+http.createServer(function (req, res) {
+ var daQuery, fromPerson, toSay;
+ res.writeHead(200, {'Content-Type': 'text/html'});
+
+ daQuery = qs.parse(url.parse(req.url).query)
+ if(daQuery["say"]){
+ toSay = daQuery["say"].replace(/[\W\s\.-\?\!]/g,' ')
+ }
+ if(daQuery["fromName"]){
+ fromPerson = daQuery["fromName"].replace(/[\W\s\.-\?\!]/g,' ')
+ }
+
+ console.log(fromPerson + " said:" + toSay)
+ messages.push(fromPerson + " said:" + toSay)
+
+ req.on('end',function(){
+ if(toSay){
+ if(fromPerson){
+ exec('say -v "Kathy" ' + fromPerson + ' said ', function()
+ {
+ exec('say "' + toSay +'"')
+ })
+ }else{
+ exec('say "' + toSay +'"')
+ }
+ }
+ })
+ res.end('<form>your name:<input name="fromName"><br />message:<input name="say"><input type="submit"></form>Listen!<br/>' + messages.join('<br/>'));
+
+
+}).listen(1337, '0.0.0.0');
+
+console.log('Server running at http://127.0.0.1:1337/');
+console.log("Just visit with ...:1337/?say=Your Message Here")
+
+console.log(os.networkInterfaces())
Please sign in to comment.
Something went wrong with that request. Please try again.