|
@ -4,13 +4,14 @@ var connect = require("connect"), |
|
|
Thing = require("nature").Thing, |
|
|
Thing = require("nature").Thing, |
|
|
wodge = require("wodge"); |
|
|
wodge = require("wodge"); |
|
|
|
|
|
|
|
|
|
|
|
var usage = "usage: ws [--port|-p <port>] [--log-format|-f dev|default|short|tiny]"; |
|
|
|
|
|
|
|
|
function halt(message){ |
|
|
function halt(message){ |
|
|
console.log(wodge.red("Error ") + message); |
|
|
console.log(wodge.red("Error ") + message); |
|
|
console.log(usage); |
|
|
console.log(usage); |
|
|
process.exit(1); |
|
|
process.exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var usage = "usage: ws [--port|-p <port>] [--log-format|-f dev|default|short|tiny]"; |
|
|
|
|
|
var options = new Thing() |
|
|
var options = new Thing() |
|
|
.define({ name: "port", alias: "p", type: "number", defaultOption: true, value: 8000 }) |
|
|
.define({ name: "port", alias: "p", type: "number", defaultOption: true, value: 8000 }) |
|
|
.define({ name: "log-format", alias: "f", type: "string", value: "dev" }) |
|
|
.define({ name: "log-format", alias: "f", type: "string", value: "dev" }) |
|
@ -21,7 +22,7 @@ var options = new Thing() |
|
|
.set(process.argv); |
|
|
.set(process.argv); |
|
|
|
|
|
|
|
|
if (!options.valid){ |
|
|
if (!options.valid){ |
|
|
halt(options.validationMessages) |
|
|
|
|
|
|
|
|
halt(options.validationMessages); |
|
|
|
|
|
|
|
|
} else if (options.help){ |
|
|
} else if (options.help){ |
|
|
console.log(usage); |
|
|
console.log(usage); |
|
@ -30,7 +31,7 @@ if (!options.valid){ |
|
|
/** |
|
|
/** |
|
|
customised connect.logger :date token, purely to satisfy Logstalgia. |
|
|
customised connect.logger :date token, purely to satisfy Logstalgia. |
|
|
*/ |
|
|
*/ |
|
|
connect.logger.token('date', function(req, res){ |
|
|
|
|
|
|
|
|
connect.logger.token("date", function(){ |
|
|
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()) |
|
|
.replace("GMT", "").replace(" (BST)", ""); |
|
|
.replace("GMT", "").replace(" (BST)", ""); |
|
@ -45,7 +46,7 @@ if (!options.valid){ |
|
|
http.createServer(app) |
|
|
http.createServer(app) |
|
|
.on("error", function(err){ |
|
|
.on("error", function(err){ |
|
|
if (err.code === "EADDRINUSE"){ |
|
|
if (err.code === "EADDRINUSE"){ |
|
|
halt("port " + options.port + " is already is use") |
|
|
|
|
|
|
|
|
halt("port " + options.port + " is already is use"); |
|
|
} else { |
|
|
} else { |
|
|
halt(err.message); |
|
|
halt(err.message); |
|
|
} |
|
|
} |
|
|