Browse Source

stats wip

master
Lloyd Brookes 11 years ago
parent
commit
6acc0e295e
  1. 26
      ws.js

26
ws.js

@ -12,6 +12,7 @@ var options = new Thing()
.define({ name: "log-format", alias: "f", type: "string", value: "dev" }) .define({ name: "log-format", alias: "f", type: "string", value: "dev" })
.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: "stats", alias: "s", type: "boolean" })
.on("error", function(err){ .on("error", function(err){
halt(err.message); halt(err.message);
}) })
@ -47,18 +48,33 @@ if (!options.valid){
.replace("GMT", "").replace(" (BST)", ""); .replace("GMT", "").replace(" (BST)", "");
}); });
var app = connect()
.use(connect.logger(options["log-format"]))
.use(connect.compress())
var app = connect();
if(options.stats){
var reqCount = 0;
app.use(function(req, res, next){
if (reqCount === 0){
process.stdout.write("Files served: ");
}
process.stdout.write(reqCount.toString());
reqCount++;
process.stdout.write("\x1b[15G");
next();
});
} else {
app.use(connect.logger(options["log-format"]));
}
app.use(connect.compress())
.use(connect.static(options.directory)) .use(connect.static(options.directory))
.use(connect.directory(options.directory, { icons: true })); .use(connect.directory(options.directory, { icons: true }));
http.createServer(app) http.createServer(app)
.on("error", handleServerError) .on("error", handleServerError)
.listen(options.port); .listen(options.port);
/* /*
write to stderr so not to appear in logs piped to disk ($ ws > log.txt)
write to stderr so stdout can be piped to disk ($ ws > log.txt)
*/ */
console.error(util.format( console.error(util.format(
"serving %sat %s", "serving %sat %s",

Loading…
Cancel
Save