|
@ -3,7 +3,6 @@ |
|
|
require("console-dope"); |
|
|
require("console-dope"); |
|
|
var connect = require("connect"), |
|
|
var connect = require("connect"), |
|
|
http = require("http"), |
|
|
http = require("http"), |
|
|
util = require("util"), |
|
|
|
|
|
fs = require("fs"), |
|
|
fs = require("fs"), |
|
|
Thing = require("nature").Thing, |
|
|
Thing = require("nature").Thing, |
|
|
w = require("wodge"), |
|
|
w = require("wodge"), |
|
@ -17,14 +16,6 @@ function halt(message){ |
|
|
process.exit(1); |
|
|
process.exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function handleServerError(err){ |
|
|
|
|
|
if (err.code === "EADDRINUSE"){ |
|
|
|
|
|
halt("port " + argv.port + " is already is use"); |
|
|
|
|
|
} else { |
|
|
|
|
|
halt(err.message); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
parse command-line args |
|
|
parse command-line args |
|
|
*/ |
|
|
*/ |
|
@ -114,20 +105,26 @@ if (argv.help){ |
|
|
/** |
|
|
/** |
|
|
static file server including directory browsing support |
|
|
static file server including directory browsing support |
|
|
*/ |
|
|
*/ |
|
|
app.use(connect.static(argv.directory)) |
|
|
|
|
|
.use(connect.directory(argv.directory, { icons: true })); |
|
|
|
|
|
|
|
|
app.use(connect.static(path.resolve(argv.directory))) |
|
|
|
|
|
.use(connect.directory(path.resolve(argv.directory), { icons: true })); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
launch server |
|
|
launch server |
|
|
*/ |
|
|
*/ |
|
|
var server = http.createServer(app) |
|
|
var server = http.createServer(app) |
|
|
.on("error", handleServerError) |
|
|
|
|
|
|
|
|
.on("error", function(err){ |
|
|
|
|
|
if (err.code === "EADDRINUSE"){ |
|
|
|
|
|
halt("port " + argv.port + " is already is use"); |
|
|
|
|
|
} else { |
|
|
|
|
|
halt(err.message); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
.listen(argv.port); |
|
|
.listen(argv.port); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
write status to stderr so stdout can be piped to disk ($ ws > log.txt) |
|
|
write status to stderr so stdout can be piped to disk ($ ws > log.txt) |
|
|
*/ |
|
|
*/ |
|
|
if (argv.directory === process.cwd()){ |
|
|
|
|
|
|
|
|
if (path.resolve(argv.directory) === process.cwd()){ |
|
|
console.error("serving at %underline{%s}", "http://localhost:" + argv.port); |
|
|
console.error("serving at %underline{%s}", "http://localhost:" + argv.port); |
|
|
} else { |
|
|
} else { |
|
|
console.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port); |
|
|
console.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port); |
|
|