2011-11-15 16:44:47 +04:00
|
|
|
var page = require('webpage').create();
|
|
|
|
var server = require('webserver').create();
|
|
|
|
var host, port;
|
|
|
|
|
|
|
|
if (phantom.args.length !== 1) {
|
|
|
|
console.log('Usage: server.js <some port>');
|
|
|
|
phantom.exit();
|
|
|
|
} else {
|
|
|
|
port = phantom.args[0];
|
2011-11-05 19:38:08 +04:00
|
|
|
server.listen(port, function (request, response) {
|
|
|
|
console.log("GOT HTTP REQUEST: url=" + request.url() + ", method: " + request.method());
|
|
|
|
var headers = "HTTP/1.1 200 OK\r\n" +
|
|
|
|
"Cache: no-cache\r\n" +
|
|
|
|
"Content-Type: text/html\r\n" +
|
|
|
|
"\r\n";
|
|
|
|
response.writeHeaders(headers);
|
|
|
|
var contents = "<html><head><title>YES!</title></head>" +
|
|
|
|
"<body><p>pretty cool :)</body></html>";
|
|
|
|
response.writeBody(contents);
|
2011-11-15 16:44:47 +04:00
|
|
|
});
|
|
|
|
console.log("http://localhost:" + port + "/");
|
|
|
|
page.open("http://localhost:" + port + "/", function (status) {
|
|
|
|
if (status !== 'success') {
|
|
|
|
console.log('FAIL to load the address');
|
|
|
|
} else {
|
2011-11-05 19:38:08 +04:00
|
|
|
console.log(page.content);
|
2011-11-15 16:44:47 +04:00
|
|
|
}
|
|
|
|
phantom.exit();
|
|
|
|
});
|
|
|
|
}
|