Browse Source

cli options, readme

master
Lloyd Brookes 12 years ago
parent
commit
d196cd3463
  1. 19
      README.md
  2. 5
      package.json
  3. 34
      server.js

19
README.md

@ -18,4 +18,23 @@ $ ws [port]
``` ```
The `port` arg is optional, the default is 8000. The `port` arg is optional, the default is 8000.
Use with Logstalgia
===================
The `default` log format is compatible with [logstalgia](http://code.google.com/p/logstalgia/).
Write your log output to disk:
```sh
$ ws --logger default > web.log
```
Then visualise in logstalgia:
```sh
$ logstalgia web.log
```
Or pipe directly into logstalgia for real-time visualisation:
```sh
$ ws --logger default | logstalgia -
```
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/050b17b4263c08f12a2a9d9bbda80025 "githalytics.com")](http://githalytics.com/75lb/local-web-server) [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/050b17b4263c08f12a2a9d9bbda80025 "githalytics.com")](http://githalytics.com/75lb/local-web-server)

5
package.json

@ -1,6 +1,6 @@
{ {
"name": "local-web-server", "name": "local-web-server",
"version": "0.1.3",
"version": "0.1.4",
"description": "Local web server", "description": "Local web server",
"bin": { "bin": {
"ws": "./server.js" "ws": "./server.js"
@ -9,6 +9,7 @@
"author": "Lloyd Brookes", "author": "Lloyd Brookes",
"license": "BSD", "license": "BSD",
"dependencies": { "dependencies": {
"connect": "~2.7.11"
"connect": "~2.7.11",
"nature": "0.0.4"
} }
} }

34
server.js

@ -1,14 +1,27 @@
#!/usr/bin/env node #!/usr/bin/env node
var connect = require('connect');
var connect = require('connect'),
Thing = require("nature").Thing;
/**
usage:
$ ws <port> <connect-logger-profile>
*/
process.argv.splice(0, 2);
var usage = "usage: ws [--port|-p <port>] [--log-format|-p dev|default|short|tiny]";
var options = new Thing()
.define({ name: "port", alias: "p", type: "number", defaultOption: true, default: 8000 })
.define({ name: "log-format", alias: "f", type: "string", default: "dev" })
.define({ name: "help", alias: "h", type: "boolean" })
.set(process.argv);
var port = process.argv[2] || 8000,
loggerProfile = process.argv[3] || "dev";
if (!options.valid){
console.log(usage);
throw new Error(options.validationMessages);
} else if (options.help){
console.log(usage);
} else {
/**
customised connect.logger :date token, purely to satisfy Logstalgia.
*/
connect.logger.token('date', function(req, res){ connect.logger.token('date', function(req, res){
var a = new Date(); var a = new Date();
return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString()) return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString())
@ -16,9 +29,10 @@ connect.logger.token('date', function(req, res){
}); });
connect() connect()
.use(connect.logger(loggerProfile))
.use(connect.logger(options["log-format"]))
.use(connect.static(process.cwd())) .use(connect.static(process.cwd()))
.use(connect.directory(process.cwd())) .use(connect.directory(process.cwd()))
.listen(port);
.listen(options.port);
process.stderr.write("listening on port " + port + "\n");
process.stderr.write("listening on port " + options.port + "\n");
}
Loading…
Cancel
Save