source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/server.js@ 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.5 KB
Line 
1var page = require('webpage').create();
2var server = require('webserver').create();
3var system = require('system');
4var host, port;
5
6if (system.args.length !== 2) {
7 console.log('Usage: server.js <some port>');
8 phantom.exit(1);
9} else {
10 port = system.args[1];
11 var listening = server.listen(port, function (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 = {"Cache": "no-cache", "Content-Type": "text/html"};
18 // this is also possible:
19 response.setHeader("foo", "bar");
20 // now we write the body
21 // note: the headers above will now be sent implictly
22 response.write("<html><head><title>YES!</title></head>");
23 // note: writeBody can be called multiple times
24 response.write("<body><p>pretty cool :)</body></html>");
25 response.close();
26 });
27 if (!listening) {
28 console.log("could not create web server listening on port " + port);
29 phantom.exit();
30 }
31 var url = "http://localhost:" + port + "/foo/bar.php?asdf=true";
32 console.log("SENDING REQUEST TO:");
33 console.log(url);
34 page.open(url, function (status) {
35 if (status !== 'success') {
36 console.log('FAIL to load the address');
37 } else {
38 console.log("GOT REPLY FROM SERVER:");
39 console.log(page.content);
40 }
41 phantom.exit();
42 });
43}
Note: See TracBrowser for help on using the repository browser.