source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-macosx/examples/server.coffee@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 1.3 KB
Line 
1page = require("webpage").create()
2server = require("webserver").create()
3system = require("system")
4host = undefined
5port = undefined
6if system.args.length isnt 2
7 console.log "Usage: server.js <some port>"
8 phantom.exit 1
9else
10 port = system.args[1]
11 listening = server.listen(port, (request, response) ->
12 console.log "GOT HTTP REQUEST"
13 console.log JSON.stringify(request, null, 4)
14
15 # we set the headers here
16 response.statusCode = 200
17 response.headers =
18 Cache: "no-cache"
19 "Content-Type": "text/html"
20
21
22 # this is also possible:
23 response.setHeader "foo", "bar"
24
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>"
28
29 # note: writeBody can be called multiple times
30 response.write "<body><p>pretty cool :)</body></html>"
31 response.close()
32 )
33 unless listening
34 console.log "could not create web server listening on port " + port
35 phantom.exit()
36 url = "http://localhost:" + port + "/foo/bar.php?asdf=true"
37 console.log "SENDING REQUEST TO:"
38 console.log url
39 page.open url, (status) ->
40 if status isnt "success"
41 console.log "FAIL to load the address"
42 else
43 console.log "GOT REPLY FROM SERVER:"
44 console.log page.content
45 phantom.exit()
Note: See TracBrowser for help on using the repository browser.