diff --git a/README.md b/README.md index 50feb37..516088d 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Server -p, --port Web server port -f, --log-format If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev', - 'default', 'short', 'tiny' or 'logstalgia') or supply a custom format + 'combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url'). -d, --directory Root directory, defaults to the current directory -c, --compress Enables compression @@ -144,6 +144,17 @@ To view your stored defaults, run: $ ws --config ``` +##mime-types +You can set additional mime-type/extension mappings, or override the defaults by setting a `mime` value in your local config. This value is passed directly to [mime.define()](https://github.com/broofa/node-mime#mimedefine). Example: + +```json +{ + "mime": { + "text/plain": [ "php", "pl" ] + } +} +``` + ##Use with Logstalgia local-web-server is compatible with [logstalgia](http://code.google.com/p/logstalgia/). diff --git a/bin/ws.js b/bin/ws.js index 4baab1f..715f59e 100755 --- a/bin/ws.js +++ b/bin/ws.js @@ -47,7 +47,8 @@ var storedConfig = loadConfig( var builtInDefaults = { port: 8000, directory: process.cwd(), - "refresh-rate": 500 + "refresh-rate": 500, + mime: {} }; /* override built-in defaults with stored config and then command line args */ @@ -98,7 +99,7 @@ if (argv.Misc.config){ } app.use(morgan(logFormat)); - } + } /* if no `--log-format` was specified, pipe the default format output into `log-stats`, which prints statistics to the console */ @@ -110,6 +111,9 @@ if (argv.Misc.config){ /* --compress enables compression */ if (argv.Server.compress) app.use(compress()); + /* set the mime-type overrides specified in the config */ + serveStatic.mime.define(argv.Server.mime); + /* enable static file server, including directory browsing support */ app.use(serveStatic(path.resolve(argv.Server.directory))) .use(directory(path.resolve(argv.Server.directory), { icons: true })); diff --git a/lib/cli-options.js b/lib/cli-options.js index 36e9d0b..5d0dab4 100644 --- a/lib/cli-options.js +++ b/lib/cli-options.js @@ -8,7 +8,7 @@ module.exports = [ }, { name: "log-format", alias: "f", type: String, - description: "If a format is supplied an access log is written to stdout. If not, \na statistics view is displayed. Use a preset ('none', 'dev',\n'default', 'short', 'tiny' or 'logstalgia') or supply a custom format\n(e.g. ':method -> :url')." + description: "If a format is supplied an access log is written to stdout. If not, \na statistics view is displayed. Use a preset ('none', 'dev',\n'combined', 'short', 'tiny' or 'logstalgia') or supply a custom format\n(e.g. ':method -> :url')." }, { name: "directory", alias: "d", type: String, diff --git a/package.json b/package.json index c075439..888e643 100644 --- a/package.json +++ b/package.json @@ -26,5 +26,10 @@ "serve-static": "^1.2.2", "stream-log-stats": "^0.1.0", "typical": "^1.0.0" + }, + "local-web-server": { + "mime": { + "text/plain": ["php"] + } } } diff --git a/test/.local-web-server.json b/test/.local-web-server.json new file mode 100644 index 0000000..611caff --- /dev/null +++ b/test/.local-web-server.json @@ -0,0 +1,5 @@ +{ + "mime": { + "text/plain": [ "php" ] + } +} diff --git a/test/something.php b/test/something.php new file mode 100644 index 0000000..abb2fca --- /dev/null +++ b/test/something.php @@ -0,0 +1 @@ +