Skip to content

Commit

Permalink
Merge pull request #27 from nodeapps/defaultExt
Browse files Browse the repository at this point in the history
Support serving files with default extension
  • Loading branch information
indexzero committed Nov 13, 2012
2 parents a0d5419 + ae043a5 commit f5790a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions bin/http-server
Expand Up @@ -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'));
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion lib/http-server.js
Expand Up @@ -25,11 +25,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
})
],
headers: this.headers || {}
Expand Down

0 comments on commit f5790a2

Please sign in to comment.