Browse Source

fixed refresh-rate issue, readme updated

master
Lloyd Brookes 11 years ago
parent
commit
68ebf8cf6f
  1. 41
      README.md
  2. 12
      bin/ws.js
  3. 4
      lib/cli-options.js
  4. 3
      package.json

41
README.md

@ -28,17 +28,18 @@ $ ws --config
$ ws --help
Server
-p, --port <number> Web server port
-f, --log-format <string> If a format is supplied an access log is written to stdout. If not,
a statistics view is displayed. Format options: 'none', 'dev',
'default', 'short', 'tiny' or 'logstalgia'.
-d, --directory <string> Root directory, defaults to the current directory
-c, --compress Enables compression
-r, --refreshRate <number> Statistics view refresh rate in ms. Defaults to 500.
-p, --port <number> Web server port
-f, --log-format <string> 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
(e.g. ':method -> :url').
-d, --directory <string> Root directory, defaults to the current directory
-c, --compress Enables compression
-r, --refresh-rate <number> Statistics view refresh rate in ms. Defaults to 500.
Misc
-h, --help Print these usage instructions
--config Print the stored config
-h, --help Print these usage instructions
--config Print the stored config
```
From the folder you wish to serve, run:
@ -59,14 +60,27 @@ $ ws --port 9000
serving at http://localhost:9000
```
Use a built-in or custom [Connect logger format](http://www.senchalabs.org/connect/logger.html) with `--log-format`:
To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
```sh
$ ws --compress
```
###Logging
Passing a value to `--log-format` will write an access log to `stdout`.
Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset:
```sh
$ ws --log-format short
```
To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
Or a custom [morgan](https://github.com/expressjs/morgan) log format:
```sh
$ ws --compress
$ ws -f ':method -> :url'
```
Or silence:
```sh
$ ws -f none
```
Storing default options
@ -93,7 +107,8 @@ Or in a `.local-web-server.json` file stored in the directory you want to serve
Or store global defaults in a `.local-web-server.json` file in your home directory.
```json
{
"port": 3000
"port": 3000,
"refresh-rate": 1000
}
```

12
bin/ws.js

@ -4,6 +4,7 @@ var dope = require("console-dope"),
http = require("http"),
cliArgs = require("command-line-args"),
o = require("object-tools"),
t = require("typical"),
path = require("path"),
loadConfig = require("config-master"),
homePath = require("home-path"),
@ -46,12 +47,18 @@ var storedConfig = loadConfig(
var builtInDefaults = {
port: 8000,
directory: process.cwd(),
refreshRate: 500
"refresh-rate": 500
};
/* override built-in defaults with stored config and then command line args */
argv.Server = o.extend(builtInDefaults, storedConfig, argv.Server);
/* user input validation */
var logFormat = argv.Server["log-format"];
if (!t.isNumber(argv.Server.port)) {
halt("please supply a numeric port value");
}
if (argv.Misc.config){
dope.log("Stored config: ");
dope.log(storedConfig);
@ -76,7 +83,6 @@ if (argv.Misc.config){
});
/* log using --log-format (if supplied) */
var logFormat = argv.Server["log-format"];
if(logFormat) {
if (logFormat === "none"){
// do nothing, no logging required
@ -98,7 +104,7 @@ if (argv.Misc.config){
into `log-stats`, which prints statistics to the console */
} else {
dope.hideCursor();
app.use(morgan({ stream: logStats({ refreshRate: argv.Server.refreshRate }) }));
app.use(morgan({ stream: logStats({ refreshRate: argv.Server["refresh-rate"] }) }));
}
/* --compress enables compression */

4
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. Format options: 'none', 'dev',\n'default', 'short', 'tiny' or 'logstalgia'."
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')."
},
{
name: "directory", alias: "d", type: String,
@ -19,7 +19,7 @@ module.exports = [
description: "Enables compression"
},
{
name: "refreshRate", alias: "r", type: Number,
name: "refresh-rate", alias: "r", type: Number,
description: "Statistics view refresh rate in ms. Defaults to 500."
}
]

3
package.json

@ -24,6 +24,7 @@
"object-tools": "^1.0.3",
"serve-index": "^1.0.2",
"serve-static": "^1.2.2",
"stream-log-stats": "^0.1.0"
"stream-log-stats": "^0.1.0",
"typical": "^1.0.0"
}
}
Loading…
Cancel
Save