Browse Source

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

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

2
.jshintrc

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

25
ws.js

@ -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
*/ */
@ -37,7 +28,7 @@ var argv = new Thing()
.on("error", function(err){ .on("error", function(err){
halt(err.message); halt(err.message);
}); });
/* /*
Set default options from "package.json", ".local-web-server.json" or "~/.local-web-server.json", in that order Set default options from "package.json", ".local-web-server.json" or "~/.local-web-server.json", in that order
*/ */
@ -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);

Loading…
Cancel
Save