Created
October 17, 2012 17:55
-
-
Save srikumarks/3907030 to your computer and use it in GitHub Desktop.
The arc challenge using IO.WebServer.js
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
// This server doesn't suffer from the problem | |
// mentioned in http://arclanguage.org/item?id=1263 | |
// | |
// Run by placing this file alongside IO.WebServer.js | |
// and IO.js and invoking node as - | |
// node arc.js | |
// | |
// Then visit http://localhost:9000/said in your browser. | |
var IO = require('./IO.WebServer.js'); | |
var ws = IO.WebServer(9000); | |
ws.route('/said', wr([ | |
'<form name="input" action="/click" method="post">', | |
'<input type="text" name="blabberings"/>', | |
'<input type="submit" value="Submit"/>', | |
'</form>' | |
].join('') | |
)); | |
ws.route('/click', IO.do([ | |
ws.expire(10), // Optional: Expire the session after 10 seconds once you come here. | |
wr(function (W, conn) { | |
return '<a href="' + W.link(wr('you said: <b>' + conn.data.blabberings + '</b>')) + '">click here</a>'; | |
}) | |
])); | |
ws.start(); | |
function wr(x) { | |
return ws.page(ws.write(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment