Skip to content
Browse files

Merge pull request #27 from nodeapps/defaultExt

Support serving files with default extension
  • Loading branch information...
2 parents a0d5419 + ae043a5 commit f5790a21533ffe8acb8aa639cc1970a8d286d690 @indexzero committed
Showing with 15 additions and 5 deletions.
  1. +6 −4 bin/http-server
  2. +9 −1 lib/http-server.js
View
10 bin/http-server
@@ -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
10 lib/http-server.js
@@ -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 || {}

0 comments on commit f5790a2

Please sign in to comment.
Something went wrong with that request. Please try again.