Permalink
Browse files

[bin api] Added `ext` option to support proposed `defaultExt` option …

…in ecstatic
  • Loading branch information...
1 parent b9def93 commit ae043a51cdd2cb137f0f0a9baf0b7e29870e78f7 @indexzero committed Nov 10, 2012
Showing with 15 additions and 5 deletions.
  1. +6 −4 bin/http-server
  2. +9 −1 lib/http-server.js
View
@@ -13,6 +13,7 @@ if (argv.h || argv.help) {
" -p Port to use [8080]",
" -a Address to use [0.0.0.0]",
" -i Display autoIndex [true]",
+ " -e --ext Default file extension if none supplied [none]",
" -s --silent Suppress log messages from output",
" -h --help Print this list and exit.",
].join('\n'));
@@ -34,12 +35,13 @@ if (!argv.p) {
}
function listen(port) {
- var options = {
+ var server = httpServer.createServer({
root: argv._[0],
autoIndex: argv.i,
- cache: argv.c
- };
- var server = httpServer.createServer(options);
+ cache: argv.c,
+ ext: argv.e || argv.ext
+ });
+
server.listen(port, host, function() {
log('Starting up http-server, serving '.yellow
+ server.root.cyan
View
@@ -21,11 +21,19 @@ var HTTPServer = exports.HTTPServer = function (options) {
this.cache = options.cache || 3600; // in seconds.
this.autoIndex = options.autoIndex !== false;
+
+ if (options.ext) {
+ this.ext = options.ext === true
+ ? 'html'
+ : options.ext;
+ }
+
this.server = union.createServer({
before: [
ecstatic(this.root, {
autoIndex: this.autoIndex,
- cache: this.cache
+ cache: this.cache,
+ defaultExt: this.ext
})
]
});

0 comments on commit ae043a5

Please sign in to comment.