|
@ -1,16 +1,17 @@ |
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
#!/usr/bin/env node
|
|
|
var connect = require("connect"), |
|
|
var connect = require("connect"), |
|
|
http = require("http"), |
|
|
http = require("http"), |
|
|
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,16 +22,16 @@ 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); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
/** |
|
|
/** |
|
|
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)", ""); |
|
@ -41,11 +42,11 @@ if (!options.valid){ |
|
|
.use(connect.compress()) |
|
|
.use(connect.compress()) |
|
|
.use(connect.static(process.cwd())) |
|
|
.use(connect.static(process.cwd())) |
|
|
.use(connect.directory(process.cwd(), { icons: true })); |
|
|
.use(connect.directory(process.cwd(), { icons: true })); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
} |
|
|
} |
|
|