Browse Source

--compress added

master
Lloyd Brookes 11 years ago
parent
commit
bcf8a4362f
  1. 7
      README.md
  2. 18
      ws.js

7
README.md

@ -21,7 +21,7 @@ $ npm install -g local-web-server
Usage Usage
----- -----
``` ```
ws [--directory|-d <directory>] [--port|-p <port>] [--log-format|-f dev|default|short|tiny]
ws [--directory|-d <directory>] [--port|-p <port>] [--log-format|-f dev|default|short|tiny] [--compress|-c]
``` ```
From the folder you wish to serve, run: From the folder you wish to serve, run:
@ -47,6 +47,11 @@ Use a built-in or custom [Connect logger format](http://www.senchalabs.org/conne
$ ws --log-format short $ ws --log-format short
``` ```
To add compression, reducing bandwidth, increasing page load time (by 10-15% on my Macbook Air)
```sh
$ ws --compress
```
Use with Logstalgia Use with Logstalgia
------------------- -------------------
The "default" log-format is compatible with [logstalgia](http://code.google.com/p/logstalgia/). The "default" log-format is compatible with [logstalgia](http://code.google.com/p/logstalgia/).

18
ws.js

@ -23,6 +23,7 @@ var argv = new Thing()
.define({ name: "log-format", alias: "f", type: "string" }) .define({ name: "log-format", alias: "f", type: "string" })
.define({ name: "help", alias: "h", type: "boolean" }) .define({ name: "help", alias: "h", type: "boolean" })
.define({ name: "directory", alias: "d", type: "string", value: process.cwd() }) .define({ name: "directory", alias: "d", type: "string", value: process.cwd() })
.define({ name: "compress", alias: "c", type: "boolean" })
.on("error", function(err){ .on("error", function(err){
halt(err.message); halt(err.message);
}) })
@ -71,6 +72,9 @@ if (argv.help){
var app = connect(); var app = connect();
/*
log using --log-format (if supplied), else output statics
*/
if(argv["log-format"]){ if(argv["log-format"]){
app.use(connect.logger(argv["log-format"])); app.use(connect.logger(argv["log-format"]));
} else { } else {
@ -80,9 +84,20 @@ if (argv.help){
}); });
} }
/**
--compress enables compression
*/
if (argv.compress) app.use(connect.compress());
/**
static file server including directory browsing support
*/
app.use(connect.static(argv.directory)) app.use(connect.static(argv.directory))
.use(connect.directory(argv.directory, { icons: true })); .use(connect.directory(argv.directory, { icons: true }));
/**
launch server
*/
var server = http.createServer(app) var server = http.createServer(app)
.on("error", handleServerError) .on("error", handleServerError)
.listen(argv.port); .listen(argv.port);
@ -96,6 +111,9 @@ if (argv.help){
console.error("serving %u{%s} at %u{%s}", argv.directory, "http://localhost:" + argv.port); console.error("serving %u{%s} at %u{%s}", argv.directory, "http://localhost:" + argv.port);
} }
/**
in stats mode, monitor connections and bytes transferred
*/
if (!argv["log-format"]){ if (!argv["log-format"]){
console.hide(); console.hide();
console.log("%u{Requests} %u{Data} %u{Connections}"); console.log("%u{Requests} %u{Data} %u{Connections}");

Loading…
Cancel
Save