Skip to content

Commit cf63eb7

Browse files
committed
[revert] Bad option parsing code. Force pushing v0.2.3
1 parent f7a3676 commit cf63eb7

File tree

2 files changed

+40
-54
lines changed

2 files changed

+40
-54
lines changed

bin/http-server

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
11
#!/usr/bin/env node
22

3-
var HTTPServer = require('../lib/http-server').HTTPServer,
4-
colors = require('colors'),
5-
argv = require('optimist').argv;
6-
7-
if (argv.h || argv.help) {
8-
return showHelp();
9-
}
10-
11-
var httpServer = new HTTPServer({
12-
root: argv._[0] || ".",
13-
port: argv.p || 8080,
14-
host: argv.a || 'localhost',
15-
cache: argv.c || 3600,
16-
autoIndex: argv.i || true,
17-
silent: argv.s || argv.silent || false
18-
});
19-
20-
21-
httpServer.log('Starting up http-server, serving '.yellow
22-
+ httpServer.root.cyan
23-
+ ' on port: '.yellow
24-
+ httpServer.port.toString().cyan);
3+
var HTTPServer = require('../lib/http-server').HTTPServer;
254

5+
var httpServer = new HTTPServer();
266

277
httpServer.start();
288

29-
httpServer.log('http-server successfully started: '.green
30-
+ 'http://'.cyan
31-
+ httpServer.host.cyan
32-
+ ':'.cyan
33-
+ httpServer.port.toString().cyan);
34-
httpServer.log('Hit CTRL-C to stop the server')
35-
369
process.on('SIGINT', function() {
3710
httpServer.log('http-server stopped.'.red);
3811
return process.exit();
3912
});
40-
41-
function showHelp() {
42-
var help = [
43-
"usage: http-server [path] [options]",
44-
"",
45-
"options:",
46-
" -p Port to use [8080]",
47-
" -a Address to use [localhost]",
48-
" -i Display autoIndex [true]",
49-
" -s --silent Suppress log messages from output",
50-
" -h --help Print this list and exit.",
51-
].join('\n');
52-
console.log(help);
53-
}

lib/http-server.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,46 @@
66
*
77
*/
88

9-
var static = require('../vendor/node-static/lib/node-static'),
9+
var colors = require('colors'),
10+
argv = require('optimist').argv,
11+
static = require('../vendor/node-static/lib/node-static'),
1012
http = require('http');
1113

1214
var HTTPServer = exports.HTTPServer = function (options) {
13-
var defaults = {
14-
root: options.root || ".",
15-
port: options.port || 8080,
16-
host: options.host || 'localhost',
17-
cache: options.cache || 3600,
18-
autoIndex: options.autoIndex || true,
19-
silent: options.silent || false
20-
}
15+
this.root = argv._[0] || ".";
16+
this.port = argv.p || 8080;
17+
this.host = argv.a || 'localhost';
18+
this.cache = argv.c || 3600;
19+
this.autoIndex = argv.i || true;
20+
this.silent = argv.s || argv.silent || false;
2121
for (var o in options) {
22-
this[o] = options[o] || defaults[o];
22+
this[o] = options[o];
2323
}
2424
this.file = new(static.Server)(this.root, { autoIndex: this.autoIndex, cache: Number(this.cache) });
2525
}
26+
2627

2728
HTTPServer.prototype.start = function () {
2829
var self = this;
30+
if (argv.h || argv.help) {
31+
return showHelp();
32+
}
33+
self.log('Starting up http-server, serving '.yellow
34+
+ self.root.cyan
35+
+ ' on port: '.yellow
36+
+ self.port.toString().cyan);
2937
http.createServer(function(request, response) {
3038
request.on('end', function() {
31-
self.log('[served] ' + request.url);
39+
self.log('['.grey+'served'.yellow+'] '.grey + request.url);
3240
return self.file.serve(request, response);
3341
});
3442
}).listen(self.port);
43+
self.log('http-server successfully started: '.green
44+
+ 'http://'.cyan
45+
+ self.host.cyan
46+
+ ':'.cyan
47+
+ self.port.toString().cyan);
48+
self.log('Hit CTRL-C to stop the server')
3549
}
3650

3751
HTTPServer.prototype.log = function (message) {
@@ -40,3 +54,16 @@ HTTPServer.prototype.log = function (message) {
4054
}
4155
}
4256

57+
function showHelp() {
58+
var help = [
59+
"usage: http-server [path] [options]",
60+
"",
61+
"options:",
62+
" -p Port to use [8080]",
63+
" -a Address to use [localhost]",
64+
" -i Display autoIndex [true]",
65+
" -s --silent Suppress log messages from output",
66+
" -h --help Print this list and exit.",
67+
].join('\n');
68+
console.log(help);
69+
}

0 commit comments

Comments
 (0)