Skip to content

Instantly share code, notes, and snippets.

@tanabe
Created June 12, 2012 15:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanabe/2918306 to your computer and use it in GitHub Desktop.
Save tanabe/2918306 to your computer and use it in GitHub Desktop.
phantom.js webserver
(function() {
var server = require('webserver').create();
var service = server.listen(9876, function (request, response) {
var fs = require('fs');
var file = fs.read(fs.workingDirectory + request.url);
response.statusCode = 200;
response.headers['Content-Type'] = 'text/html';
response.write(file);
response.close();
});
var page = require('webpage').create();
page.onConsoleMessage = function(message) {
console.log(message);
};
page.open('http://localhost:9876/aaa.html', function(status) {
page.evaluate(function() {
console.log(location.href);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment