Browse Source

fixed when using --directory with '.' or '..'

master
Lloyd Brookes 11 years ago
parent
commit
62e30373a2
  1. 2
      .jshintrc
  2. 23
      ws.js

2
.jshintrc

@ -14,5 +14,5 @@
"quotmark": "double",
"trailing": true,
"undef": true,
"unused": "strict"
"unused": true
}

23
ws.js

@ -3,7 +3,6 @@
require("console-dope");
var connect = require("connect"),
http = require("http"),
util = require("util"),
fs = require("fs"),
Thing = require("nature").Thing,
w = require("wodge"),
@ -17,14 +16,6 @@ function halt(message){
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
*/
@ -114,20 +105,26 @@ if (argv.help){
/**
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
*/
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);
/*
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);
} else {
console.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port);

Loading…
Cancel
Save