1 page = require("webpage").create()
2 server = require("webserver").create()
3 system = require("system")
6 if system.args.length isnt 2
7 console.log "Usage: server.js <some port>"
11 listening = server.listen(port, (request, response) ->
12 console.log "GOT HTTP REQUEST"
13 console.log JSON.stringify(request, null, 4)
15 # we set the headers here
16 response.statusCode = 200
19 "Content-Type": "text/html"
22 # this is also possible:
23 response.setHeader "foo", "bar"
25 # now we write the body
26 # note: the headers above will now be sent implictly
27 response.write "<html><head><title>YES!</title></head>"
29 # note: writeBody can be called multiple times
30 response.write "<body><p>pretty cool :)</body></html>"
34 console.log "could not create web server listening on port " + port
36 url = "http://localhost:" + port + "/foo/bar.php?asdf=true"
37 console.log "SENDING REQUEST TO:"
39 page.open url, (status) ->
40 if status isnt "success"
41 console.log "FAIL to load the address"
43 console.log "GOT REPLY FROM SERVER:"
44 console.log page.content