fixed refresh-rate issue, readme updated
This commit is contained in:
41
README.md
41
README.md
@ -28,17 +28,18 @@ $ ws --config
|
|||||||
$ ws --help
|
$ ws --help
|
||||||
|
|
||||||
Server
|
Server
|
||||||
-p, --port <number> Web server port
|
-p, --port <number> Web server port
|
||||||
-f, --log-format <string> If a format is supplied an access log is written to stdout. If not,
|
-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',
|
a statistics view is displayed. Use a preset ('none', 'dev',
|
||||||
'default', 'short', 'tiny' or 'logstalgia'.
|
'default', 'short', 'tiny' or 'logstalgia') or supply a custom format
|
||||||
-d, --directory <string> Root directory, defaults to the current directory
|
(e.g. ':method -> :url').
|
||||||
-c, --compress Enables compression
|
-d, --directory <string> Root directory, defaults to the current directory
|
||||||
-r, --refreshRate <number> Statistics view refresh rate in ms. Defaults to 500.
|
-c, --compress Enables compression
|
||||||
|
-r, --refresh-rate <number> Statistics view refresh rate in ms. Defaults to 500.
|
||||||
|
|
||||||
Misc
|
Misc
|
||||||
-h, --help Print these usage instructions
|
-h, --help Print these usage instructions
|
||||||
--config Print the stored config
|
--config Print the stored config
|
||||||
```
|
```
|
||||||
|
|
||||||
From the folder you wish to serve, run:
|
From the folder you wish to serve, run:
|
||||||
@ -59,14 +60,27 @@ $ ws --port 9000
|
|||||||
serving at http://localhost: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
|
```sh
|
||||||
$ ws --log-format short
|
$ 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
|
```sh
|
||||||
$ ws --compress
|
$ ws -f ':method -> :url'
|
||||||
|
```
|
||||||
|
|
||||||
|
Or silence:
|
||||||
|
```sh
|
||||||
|
$ ws -f none
|
||||||
```
|
```
|
||||||
|
|
||||||
Storing default options
|
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.
|
Or store global defaults in a `.local-web-server.json` file in your home directory.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"port": 3000
|
"port": 3000,
|
||||||
|
"refresh-rate": 1000
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
12
bin/ws.js
12
bin/ws.js
@ -4,6 +4,7 @@ var dope = require("console-dope"),
|
|||||||
http = require("http"),
|
http = require("http"),
|
||||||
cliArgs = require("command-line-args"),
|
cliArgs = require("command-line-args"),
|
||||||
o = require("object-tools"),
|
o = require("object-tools"),
|
||||||
|
t = require("typical"),
|
||||||
path = require("path"),
|
path = require("path"),
|
||||||
loadConfig = require("config-master"),
|
loadConfig = require("config-master"),
|
||||||
homePath = require("home-path"),
|
homePath = require("home-path"),
|
||||||
@ -46,12 +47,18 @@ var storedConfig = loadConfig(
|
|||||||
var builtInDefaults = {
|
var builtInDefaults = {
|
||||||
port: 8000,
|
port: 8000,
|
||||||
directory: process.cwd(),
|
directory: process.cwd(),
|
||||||
refreshRate: 500
|
"refresh-rate": 500
|
||||||
};
|
};
|
||||||
|
|
||||||
/* override built-in defaults with stored config and then command line args */
|
/* override built-in defaults with stored config and then command line args */
|
||||||
argv.Server = o.extend(builtInDefaults, storedConfig, argv.Server);
|
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){
|
if (argv.Misc.config){
|
||||||
dope.log("Stored config: ");
|
dope.log("Stored config: ");
|
||||||
dope.log(storedConfig);
|
dope.log(storedConfig);
|
||||||
@ -76,7 +83,6 @@ if (argv.Misc.config){
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* log using --log-format (if supplied) */
|
/* log using --log-format (if supplied) */
|
||||||
var logFormat = argv.Server["log-format"];
|
|
||||||
if(logFormat) {
|
if(logFormat) {
|
||||||
if (logFormat === "none"){
|
if (logFormat === "none"){
|
||||||
// do nothing, no logging required
|
// do nothing, no logging required
|
||||||
@ -98,7 +104,7 @@ if (argv.Misc.config){
|
|||||||
into `log-stats`, which prints statistics to the console */
|
into `log-stats`, which prints statistics to the console */
|
||||||
} else {
|
} else {
|
||||||
dope.hideCursor();
|
dope.hideCursor();
|
||||||
app.use(morgan({ stream: logStats({ refreshRate: argv.Server.refreshRate }) }));
|
app.use(morgan({ stream: logStats({ refreshRate: argv.Server["refresh-rate"] }) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --compress enables compression */
|
/* --compress enables compression */
|
||||||
|
@ -8,7 +8,7 @@ module.exports = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "log-format", alias: "f", type: String,
|
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,
|
name: "directory", alias: "d", type: String,
|
||||||
@ -19,7 +19,7 @@ module.exports = [
|
|||||||
description: "Enables compression"
|
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."
|
description: "Statistics view refresh rate in ms. Defaults to 500."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
"object-tools": "^1.0.3",
|
"object-tools": "^1.0.3",
|
||||||
"serve-index": "^1.0.2",
|
"serve-index": "^1.0.2",
|
||||||
"serve-static": "^1.2.2",
|
"serve-static": "^1.2.2",
|
||||||
"stream-log-stats": "^0.1.0"
|
"stream-log-stats": "^0.1.0",
|
||||||
|
"typical": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user