|
|
@ -7,12 +7,13 @@ var util = require('util'), |
|
|
|
events = require('events'); |
|
|
|
events = require('events'); |
|
|
|
|
|
|
|
|
|
|
|
var DEFAULT_PORT = 8000; |
|
|
|
var DEFAULT_PORT = 8000; |
|
|
|
|
|
|
|
var DEFAULT_HOST = 'localhost'; |
|
|
|
|
|
|
|
|
|
|
|
function main(argv) { |
|
|
|
function main(argv) { |
|
|
|
new HttpServer({ |
|
|
|
new HttpServer({ |
|
|
|
'GET': createServlet(StaticServlet), |
|
|
|
'GET': createServlet(StaticServlet), |
|
|
|
'HEAD': createServlet(StaticServlet) |
|
|
|
'HEAD': createServlet(StaticServlet) |
|
|
|
}).start(Number(argv[2]) || DEFAULT_PORT); |
|
|
|
}).start(Number(argv[2]) || DEFAULT_PORT, argv[3] || DEFAULT_HOST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function escapeHtml(value) { |
|
|
|
function escapeHtml(value) { |
|
|
@ -38,10 +39,11 @@ function HttpServer(handlers) { |
|
|
|
this.server = http.createServer(this.handleRequest_.bind(this)); |
|
|
|
this.server = http.createServer(this.handleRequest_.bind(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HttpServer.prototype.start = function(port) { |
|
|
|
HttpServer.prototype.start = function(port, host) { |
|
|
|
this.port = port; |
|
|
|
this.port = port; |
|
|
|
this.server.listen(port); |
|
|
|
this.host = host; |
|
|
|
util.puts('Http Server running at http://localhost:' + port + '/'); |
|
|
|
this.server.listen(port, host); |
|
|
|
|
|
|
|
util.puts('Http Server running at http://' + host + ':' + port + '/'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
HttpServer.prototype.parseUrl_ = function(urlString) { |
|
|
|
HttpServer.prototype.parseUrl_ = function(urlString) { |
|
|
|