2015-04-10 10:51:00 +03:00
|
|
|
"use strict";
|
2012-03-15 11:59:06 +04:00
|
|
|
var port, server, service,
|
|
|
|
system = require('system');
|
2012-03-13 20:41:49 +04:00
|
|
|
|
2012-03-15 11:59:06 +04:00
|
|
|
if (system.args.length !== 2) {
|
2012-03-13 20:41:49 +04:00
|
|
|
console.log('Usage: serverkeepalive.js <portnumber>');
|
2012-05-16 11:37:26 +04:00
|
|
|
phantom.exit(1);
|
2012-03-13 20:41:49 +04:00
|
|
|
} else {
|
2012-03-15 11:59:06 +04:00
|
|
|
port = system.args[1];
|
2012-03-13 20:41:49 +04:00
|
|
|
server = require('webserver').create();
|
|
|
|
|
2012-03-14 21:51:35 +04:00
|
|
|
service = server.listen(port, { keepAlive: true }, function (request, response) {
|
2012-03-13 20:41:49 +04:00
|
|
|
console.log('Request at ' + new Date());
|
|
|
|
console.log(JSON.stringify(request, null, 4));
|
|
|
|
|
|
|
|
var body = JSON.stringify(request, null, 4);
|
|
|
|
response.statusCode = 200;
|
|
|
|
response.headers = {
|
|
|
|
'Cache': 'no-cache',
|
|
|
|
'Content-Type': 'text/plain',
|
|
|
|
'Connection': 'Keep-Alive',
|
|
|
|
'Keep-Alive': 'timeout=5, max=100',
|
|
|
|
'Content-Length': body.length
|
|
|
|
};
|
|
|
|
response.write(body);
|
|
|
|
response.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (service) {
|
|
|
|
console.log('Web server running on port ' + port);
|
|
|
|
} else {
|
|
|
|
console.log('Error: Could not create web server listening on port ' + port);
|
|
|
|
phantom.exit();
|
|
|
|
}
|
|
|
|
}
|