From 62e30373a2088f96bad797f1185d391a3603b515 Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Thu, 6 Mar 2014 14:00:50 +0100 Subject: [PATCH] fixed when using --directory with '.' or '..' --- .jshintrc | 2 +- ws.js | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.jshintrc b/.jshintrc index ef86c4c..0a54ccb 100644 --- a/.jshintrc +++ b/.jshintrc @@ -14,5 +14,5 @@ "quotmark": "double", "trailing": true, "undef": true, - "unused": "strict" + "unused": true } diff --git a/ws.js b/ws.js index 8084bbe..5c1c3e3 100755 --- a/ws.js +++ b/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 */ @@ -37,7 +28,7 @@ var argv = new Thing() .on("error", function(err){ halt(err.message); }); - + /* 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 */ - 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);